开发者

How to handle Windows Messages

开发者 https://www.devze.com 2023-04-12 02:05 出处:网络
I\'m trying to prevent a checkbox inside a ListView to get checked on a double click event. I already did:

I'm trying to prevent a checkbox inside a ListView to get checked on a double click event.

I already did:

listView.SelectedItems[0].Checked = (listView.SelectedItems[0].Checked) ? false : true;

But the checked event get called and the checkmark blinks inside the square box so I really think it sucks hard time.

开发者_运维知识库

I stumbled upon this answer: Prevent ItemChecked event on a ListView from interfering with SubItemClicked using C#

It seems to be the perfect way to do so, but I don't know how to make this work. I tried to read a bit about notifications, messages, etc but found nothing understable enough for me to apply it to my code.

Could someone shed me some light on this please?

Thank you very much!


Simply implement the ItemCheck event. You can cancel the check by changing the e.NewValue property. A silly example:

    private void listView1_ItemCheck(object sender, ItemCheckEventArgs e) {
        // Disable checking odd numbered items
        if (e.Index % 2 == 1) {
            e.NewValue = e.CurrentValue;
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消