C # ListView with CheckBoxes, automatically checked when multiple selection rows

I am using a ListView control in which you selected multirow and fullrow. When I select multiple rows at once, some of my rows are magically checked. This happens when you drag the mouse, as well as when you select one and shift by clicking on the other.

See the image describing the problem here: alt text

What is happening in grapefruit? Is anyone

+6
c # checkbox listview winforms multi-select
source share
3 answers

Unfortunately, there are errors in the ListView class, this is one of them. The following code is a fix that worked for me.

Edit: Sorry, this does not work correctly, although this prevents the error you are showing in your question. This prevents multiple items from being selected and then checked by checking the box.

void SetupListView() { listView.ItemCheck += new ItemCheckEventHandler(listView_ItemCheck); listView.MouseDown += new MouseEventHandler(listView_MouseDown); listView.MouseUp += new MouseEventHandler(listView_MouseUp); listView.MouseLeave += new EventHandler(listView_MouseLeave); } bool mouseDown = false; void listView_MouseLeave(object sender, EventArgs e) { mouseDown = false; } void listView_MouseUp(object sender, MouseEventArgs e) { mouseDown = false; } void listView_MouseDown(object sender, MouseEventArgs e) { mouseDown = true; } void listView_ItemCheck(object sender, ItemCheckEventArgs e) { if(mouseDown) { e.NewValue = e.CurrentValue; } } 
+6
source share
+3
source share

This is a simple question. Just try this.

 private void listView1_ItemCheck(object sender, ItemCheckEventArgs e) { if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Shift) { e.NewValue = e.CurrentValue; } } 
0
source share

All Articles