Change color to Listview column item

后端 未结 2 794
迷失自我
迷失自我 2021-01-28 18:50

Is it possible to change color of a specific item for specific column in Listview ?

相关标签:
2条回答
  • 2021-01-28 19:26

    As you haven't mentioned what you want to change so Below is the example to change backcolor and forecolor of a specific subitem in listview

     item1.SubItems[1].BackColor = Color.Yellow;
     item1.SubItems[1].ForeColor= Color.Yellow;
    

    You can specify your own subitem by column name.

    0 讨论(0)
  • 2021-01-28 19:27

    Given a ListView named ListView1.

    If you know the name of the column you want to change, then try this:

    foreach(ListViewItem theItem in ListView1)
    {
        if(theItem.Text == "Column Name")
        {
            theItem.ForeColor = Color.Red;
    
            // You also have access to the list view's SubItems collection
            theItem.SubItems[0].ForeColor = Color.Blue;
        }
    }
    

    Note: Obviously Column Name is made up and you would need to substitute the real column name. Also, Color.Red is made up and you can substitute whatever color you want.

    0 讨论(0)
提交回复
热议问题