ListView with Checkboxes

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

When trying to remove the icon from a ListViewItem (see code below), the icon does not always disappear. Instead, if I use another index (1, 2, etc.) then the correct icon appears. I was thinking that maybe the value "-1" is not correct. But what should be the value if someone does not want any icon?

private void listView1_ItemCheck(object sender, ItemCheckEventArgs e) {
ListViewItem itemChecked = this.listView1.Items[e.Index];
if (itemChecked.Checked == true)
itemChecked.ImageIndex = -1;
else
itemChecked.ImageIndex = 0;
}


Thanks
Mike
 
Mike said:
When trying to remove the icon from a ListViewItem (see code below), the
icon does not always disappear. Instead, if I use another index (1, 2,
etc.) then the correct icon appears. I was thinking that maybe the value
"-1" is not correct. But what should be the value if someone does not
want any icon?

private void listView1_ItemCheck(object sender, ItemCheckEventArgs e) {
ListViewItem itemChecked = this.listView1.Items[e.Index];
if (itemChecked.Checked == true)
itemChecked.ImageIndex = -1;
else
itemChecked.ImageIndex = 0;
}

Hi Mike,

I have rebuilt your solution and your code always worked fine on my
machine. -1 in my opinion is correct. Did you try to repaint the control
after changing the ImageIndex?

Cheers

Arne Janning
 
Back
Top