我使用ListView并希望用户能够从中选择一行或多行。我目前正在使用行选择,但认为使用复选框来允许用户勾选他们想要的项目是一个更直观的UI。
这是一个简单的更改,但似乎ListView的复选框功能没有响应。如果我慢慢点击复选框,他们会按预期勾选并取消勾选,但如果我连续快速点击,则会忽略定期点击。正如我所期望的那样,用户希望快速运行列表滴答/解开,这使得复选框方法无法工作。因为我需要显示多列行,所以我必须使用ListView(或它的衍生物)。
我已将ListView复选框行为与CheckedListBox进行比较,看看它是否是一个更广泛的问题,但CheckedListBox很好,从不错过点击。我在下方添加了一个示例应用来比较两者。快速点击CheckedListBox中的复选框三次就可以完美地运行。在ListView中快速点击三次总会导致错过一次点击。
由于这个问题似乎是ListView的基础,有没有人有任何想法或解决方法?
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();
}
}