问题
I have a TreeView
populated with TreeNodes
having icons and checkboxes.
I've been tryig to disable the checkig/unchecking ability of some of them discarding the event in the BerforeCheck
method. This works fine, until I double click on the checkbox: the image of the checkbox is the opposite of its real state (it shows a check mark if the status is Checked=false
). I've tried to fix that changing the StateImageIndex manually in the NodeDoubleClick
and BeforeClick
method with no success.
Even worse: I added a third image in the StateImageList
(yes I want the checkboxes to be tri-state too) but I'm not using it yet (it's never set in my code), and the third image is set as the current state of the box after some double-click (at this point I can't determine a clear behavior).
How can I do to at best make it work as exepected, at worst disable the double-click on the checkbox? Thanks.
PS: The question has already been asked, but had no answer...
回答1:
Try this.. :) worked for me
public class NewTreeView : TreeView
{
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x203)
m.Result = IntPtr.Zero;
else
base.WndProc(ref m);
}
}
来源:https://stackoverflow.com/questions/5322391/double-click-beavior-on-a-treenode-checkbox