How to handle Windows Messages
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;
}
}
精彩评论