Winforms ListView - Stop automatically checking when double clicking

后端 未结 5 1476
粉色の甜心
粉色の甜心 2021-02-19 04:15

How do I make a listview not automatically check an item when I double click it?

I can try hooking into the MouseDoubleClick event, and set the Checked property to false

5条回答
  •  悲&欢浪女
    2021-02-19 04:32

    A simple solution suggested as answer for similar question was just ok for my use:

    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;
    }
    

提交回复
热议问题