只有改变,如果该复选框被点击一个ListViewItem的的选中状态 [英] Only change a ListViewItem's Checked state if the checkbox is clicked

查看:155
本文介绍了只有改变,如果该复选框被点击一个ListViewItem的的选中状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认情况下,双击一个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:

点击时:

  1. 的MouseDown< -------------抑制区域
  2. 点击
  3. 鼠标点击
  4. 的MouseUp ------------->
  5. ItemCheck(之外抑制区域)
  6. ItemChecked
  1. MouseDown <------------- inhibited region
  2. Click
  3. MouseClick
  4. MouseUp ------------->
  5. ItemCheck (outside inhibited region)
  6. ItemChecked

当双击:

  1. 的MouseDown&LT; -------------抑制区域
  2. ItemSelectionChanged
  3. 的SelectedIndexChanged
  4. 点击
  5. 鼠标点击
  6. 的MouseUp ------------->
  7. 的MouseDown&LT; -------------抑制区域
  8. ItemCheck(抑制区域)
  9. ItemActivate
  10. 的DoubleClick
  11. MouseDoubleClick
  12. 的MouseUp ------------->
  1. MouseDown <------------- inhibited region
  2. ItemSelectionChanged
  3. SelectedIndexChanged
  4. Click
  5. MouseClick
  6. MouseUp ------------->
  7. MouseDown <------------- inhibited region
  8. ItemCheck (inside inhibited region)
  9. ItemActivate
  10. DoubleClick
  11. MouseDoubleClick
  12. MouseUp ------------->

这篇关于只有改变,如果该复选框被点击一个ListViewItem的的选中状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆