1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//test.cs
string[] dr = Directory.GetDirectories(txtStartDir.Text);
ListViewItem lv = null;
foreach (string item in dr)
{
lv = new ListViewItem(item);
//you must set this to ListViewItem
lv.UseItemStyleForSubItems = false;
lv.SubItems.Add("0");
lv.SubItems.Add("0");
lv.SubItems.Add("Ready to go!");
lv.Checked = true;
lstv.Items.Add(lv);
}
//on button click - get only the checked
foreach (ListViewItem item in lstv.CheckedItems)
{
item.SubItems[1].Text = Directory.GetFiles(item.Text, "*.pdf").Count().ToString();
item.SubItems[2].Text = Directory.GetDirectories(item.Text).Count().ToString();
//then::
item.SubItems[2].BackColor = Color.Red;
item.SubItems[2].ForeColor = Color.Yellow;
}
origin - http://www.pipiscrew.com/?p=4842 net-listview-colorize-subitems