只有改变,如果该复选框被点击一个ListViewItem的的选中状态复选框、状态、ListViewItem

由网友(日月.)分享简介:在默认情况下,双击一个ListViewItem的切换它的选中状态。我只希望选中状态,通过单击该项目的复选框或pressing空格键,同时突出显示某个项目进行更改。这是很容易做到?By default, double-clicking a ListViewItem toggles its Checked state....

在默认情况下,双击一个ListViewItem的切换它的选中状态。我只希望选中状态,通过单击该项目的复选框或pressing空格键,同时突出显示某个项目进行更改。这是很容易做到?

By default, double-clicking a ListViewItem toggles its Checked state. I only want the Checked state to be changed by clicking an the item's checkbox or pressing the space bar while an item is highlighted. Is this easy to do?

推荐答案

该解决方案包括3事件和bool类型的一个状态变量:

The solution involves 3 events and one state variable of type bool:

private bool inhibitAutoCheck;

private void listView1_MouseDown(object sender, MouseEventArgs e) {
    inhibitAutoCheck = true;
}

private void listView1_MouseUp(object sender, MouseEventArgs e) {
    inhibitAutoCheck = false;
}

private void listView1_ItemCheck(object sender, ItemCheckEventArgs e) {
    if (inhibitAutoCheck)
        e.NewValue = e.CurrentValue;
}

该项目检查能够避免过渡到另一个检查状态(ItemChecked事件之前调用)。解决的办法很简单,肯定的。

The item check enables to avoid the transition to another check state (called before the ItemChecked event). The solution is simple and sure.

要找到它我做了一个小的测试有不同的事件:

To find it out I made a small test with different events:

点击时:

的MouseDown&LT; -------------抑制区域 点击 鼠标点击 的MouseUp -------------> ItemCheck(之外抑制区域) ItemChecked MouseDown <------------- inhibited region Click MouseClick MouseUp -------------> ItemCheck (outside inhibited region) ItemChecked

当双击:

的MouseDown&LT; -------------抑制区域 ItemSelectionChanged 的SelectedIndexChanged 点击 鼠标点击 的MouseUp -------------> 的MouseDown&LT; -------------抑制区域 ItemCheck(在抑制区域) ItemActivate 的DoubleClick MouseDoubleClick 的MouseUp -------------> MouseDown <------------- inhibited region ItemSelectionChanged SelectedIndexChanged Click MouseClick MouseUp -------------> MouseDown <------------- inhibited region ItemCheck (inside inhibited region) ItemActivate DoubleClick MouseDoubleClick MouseUp ------------->
阅读全文

相关推荐

最新文章