listviewitem 子项中的颜色未突出显示

发布于 2024-12-09 01:40:30 字数 2328 浏览 0 评论 0原文

我使用此代码来隐藏偶数的前三个子项。

例如,

有 2 个 listviewitem

1) 132 |123 |123 |123 |Buy |11 |11 |11 |11

2) 132 |123 |123 |123 |Sell|22 |22 |22 |22

我这样显示它们在列表视图中,

         132 |123  |123 |123 |Buy |11 |11  |11  |11 

                             |Sell|22 |22  |22  |22 

我想将“购买”的颜色突出显示为绿色 并以红色出售

我使用此代码来显示它突出显示绿色但不突出显示红色

        int iRecords = 0;
        int iDate = 0;
        int iRecords1 = 0;
        using (var sr = File.OpenText(destination + "\\Calc.txt"))
        {
            string line;
            bool flag = true;
            int i = 0;
            while ((line = sr.ReadLine()) != null)
            {
                string[] reader2 = line.Split(',');
                string Date = reader2[0];
                string Name = reader2[1];
                string Sym = reader2[2];
                double Buy = Convert.ToDouble(reader2[3]);
                double Sell = Convert.ToDouble(reader2[4]);
                double rateBuy = Convert.ToDouble(reader2[5]);
                double rateSell = Convert.ToDouble(reader2[6]);


                ListViewItem lItem = new ListViewItem();

                if (i == 0)
                {
                    lItem = listviewrates.Items.Insert(iRecords, Date.ToString());
                    date.Text = Date;
                    lItem.UseItemStyleForSubItems = false;
                    lItem.SubItems.Add(Name.ToString());
                    lItem.SubItems.Add(Sym.ToString());
                    lItem.SubItems.Add(Buy.ToString(), Color.White, Color.Green, lItem.Font);
                    lItem.SubItems.Add(rateBuy.ToString());

                    i = 2;
                    iRecords++;
                }
                if (i == 2)
                {
                    lItem = listviewTargets.Items.Insert(iRecords, "");
                    //iRecords = iRecords - 1;
                    lItem.SubItems.Add("");
                    lItem.SubItems.Add("");
                    lItem.SubItems.Add(Sell.ToString(), Color.White, Color.Red, lItem.Font);
                    lItem.SubItems.Add(rateSell.ToString());

                    i = 0;
                    iRecords++;

                }


            }



        }

任何人都可以告诉我如何突出显示红色以进行出售。

提前致谢。

I am using this code to hide the first three subitems of even numbers .

For ex

there are 2 listviewitem

1) 132 |123 |123 |123 |Buy |11 |11 |11 |11

2) 132 |123 |123 |123 |Sell|22 |22 |22 |22

I am displaying them like this in the listview

         132 |123  |123 |123 |Buy |11 |11  |11  |11 

                             |Sell|22 |22  |22  |22 

I want to highlight the color of Buy as Green
and sell as Red

I am using this code to display it is highlighting green but not for red

        int iRecords = 0;
        int iDate = 0;
        int iRecords1 = 0;
        using (var sr = File.OpenText(destination + "\\Calc.txt"))
        {
            string line;
            bool flag = true;
            int i = 0;
            while ((line = sr.ReadLine()) != null)
            {
                string[] reader2 = line.Split(',');
                string Date = reader2[0];
                string Name = reader2[1];
                string Sym = reader2[2];
                double Buy = Convert.ToDouble(reader2[3]);
                double Sell = Convert.ToDouble(reader2[4]);
                double rateBuy = Convert.ToDouble(reader2[5]);
                double rateSell = Convert.ToDouble(reader2[6]);


                ListViewItem lItem = new ListViewItem();

                if (i == 0)
                {
                    lItem = listviewrates.Items.Insert(iRecords, Date.ToString());
                    date.Text = Date;
                    lItem.UseItemStyleForSubItems = false;
                    lItem.SubItems.Add(Name.ToString());
                    lItem.SubItems.Add(Sym.ToString());
                    lItem.SubItems.Add(Buy.ToString(), Color.White, Color.Green, lItem.Font);
                    lItem.SubItems.Add(rateBuy.ToString());

                    i = 2;
                    iRecords++;
                }
                if (i == 2)
                {
                    lItem = listviewTargets.Items.Insert(iRecords, "");
                    //iRecords = iRecords - 1;
                    lItem.SubItems.Add("");
                    lItem.SubItems.Add("");
                    lItem.SubItems.Add(Sell.ToString(), Color.White, Color.Red, lItem.Font);
                    lItem.SubItems.Add(rateSell.ToString());

                    i = 0;
                    iRecords++;

                }


            }



        }

Can any one please say me how to highlight red color for sell.

Thanks In Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪 2024-12-16 01:40:30

对于绿色项目,您做了:

lItem.useItemStyleForSubItems = false;

您还需要添加红色项目的属性,因为 lItem 是一个新对象。

if (i == 2)
{
  lItem = listviewTargets.Items.Insert(iRecords, "");

  //Fix here:
  lItem.useItemStyleForSubItems = false;

  lItem.SubItems.Add("");
  lItem.SubItems.Add("");
  lItem.SubItems.Add(Sell.ToString(), Color.White, Color.Red, lItem.Font);
  lItem.SubItems.Add(rateSell.ToString());

  i = 0;
  iRecords++;
}

For your green items, you did:

lItem.useItemStyleForSubItems = false;

You need to add the property for the red item, too, since lItem is a new object.

if (i == 2)
{
  lItem = listviewTargets.Items.Insert(iRecords, "");

  //Fix here:
  lItem.useItemStyleForSubItems = false;

  lItem.SubItems.Add("");
  lItem.SubItems.Add("");
  lItem.SubItems.Add(Sell.ToString(), Color.White, Color.Red, lItem.Font);
  lItem.SubItems.Add(rateSell.ToString());

  i = 0;
  iRecords++;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文