Alternative color in ListView C # (.Net 3.5)?

I will put an alternate color in the listview rows.
I saw this link , but I am using .Net Framework 3.5 SP1, so I can not use it.

I used the following code, but it has a problem with sorting a ListView

ListViewItem newListViewItem = new ListViewItem(
    new string[] { item.name.ToString(), 
                   item.code.ToString() });
newListViewItem.BackColor = new Color(240,240,240);
newListViewItem.UseItemStyleForSubItems = true;
newListViewItem.Font = new Font("Tahoma", 9);
listView1.Items.Add(newListViewItem);

Could you advise me how I can do this?

+3
source share
2 answers

, , . , , . , , .

, , . , BackColor.

    private static void recolorListItems(ListView lv) {
        for (int ix = 0; ix < lv.Items.Count; ++ix) {
            var item = lv.Items[ix];
            item.BackColor = (ix % 2 == 0) ? Color.Beige : Color.White;
        }
    }

. ListView. , , .

+8

0

Source: https://habr.com/ru/post/1771104/


All Articles