I'm using a ListView and want users to be able to select one or more rows from it. I'm currently using row selection but think it would be a more intuitive UI to have checkboxes to allow the user to tick the items they want.
This was a simple change, but it seems that the checkbox functionality of ListView is unresponsive. If I slowly click on checkboxes, they tick and untick as expected, but if I make quick clicks in succession, clicks regularly are ignored. As I expect users will want to quickly run down the list ticking/unticking, this makes the checkbox approach unworkable. Because I need to show multi-column rows, I have to use a ListView (or derivative of it).
I've compared the ListView checkbox behaviour to CheckedListBox, to see if it was a wider problem, but CheckedListBox is fine, never missing a click. I've included a sample app below to compare the two. Three quick clicks on a checkbox in the CheckedListBox works perfectly. Three quick clicks in ListView always results in one click being missed.
Since this problem seems fundamental to ListView, does anyone have any ideas or workarounds?
using System;
using System.Windows.Forms;
public class CheckBoxTest : Form
{
public CheckBoxTest()
{
//set up the list view
ListView lv = new ListView();
lv.FullRowSelect = true;
lv.CheckBoxes = true;
lv.View = View.Details;
lv.Columns.Add("Col1");
lv.Columns.Add("Col2");
lv.Columns.Add("Col3");
lv.Items.Add(new ListViewItem(new string[] { "a", "b", "c" }));
lv.Items.Add(new ListViewItem(new string[] { "a", "b", "c" }));
lv.Items.Add(new ListViewItem(new string[] { "a", "b", "c" }));
lv.Items.Add(new ListViewItem(new string[] { "a", "b", "c" }));
lv.Items.Add(new ListViewItem(new string[] { "a", "b", "c" }));
lv.Items.Add(new ListViewItem(new string[] { "a", "b", "c" }));
lv.Bounds = new System.Drawing.Rectangle(0, 0, 200, 200);
this.Controls.Add(lv);
//set up the list box
CheckedListBox lb = new CheckedListBox();
lb.CheckOnClick = true;
lb.Items.Add("1");
lb.Items.Add("2");
lb.Items.Add("3");
lb.Items.Add("4");
lb.Items.Add("5");
lb.Items.Add("6");
lb.Bounds = new System.Drawing.Rectangle(210, 0, 200, 200);
this.Controls.Add(lb);
this.ClientSize = new System.Drawing.Size(410, 200);
this.Text = "CheckBox Test";
}
[STAThread]
static void Main(String[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
CheckBoxTest s = new CheckBoxTest();
s.Show();
Application.Run();
}
}