C# ListView Detail, Highlight a single cell

后端 未结 3 1758
既然无缘
既然无缘 2021-01-02 04:45

I\'m using a ListView in C# to make a grid. I would like to find out a way to be able to highlight a specific cell, programatically. I only need to highlight one cell.

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 05:32

    In my case, I wanted to highlight specific rows, including all the fields. So every row in my listview with "Medicare" in the first column gets the entire row highlighted:

    public void HighLightListViewRows(ListView xLst)
            {
                for (int i = 0; i < xLst.Items.Count; i++)
                {
                    if (xLst.Items[i].SubItems[0].Text.ToString() == "Medicare")
                    {
                        for (int x = 0; x < xLst.Items[i].SubItems.Count; x++)
                        {
                            xLst.Items[i].SubItems[x].BackColor = Color.Yellow;
                        }
                    }
                }
            }
    

提交回复
热议问题