4

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...

Community
  • 1
  • 1
gregseth
  • 12,952
  • 15
  • 63
  • 96
  • I tested it and basically when you double-click a checkbox the check-change is detected only once. What's exactly the problem ? Can you post some code ? – digEmAll Mar 16 '11 at 08:18
  • P.S. I'm using XP at the moment, perhaps it's a vista/seven problem only... – digEmAll Mar 16 '11 at 08:30
  • The problem is that after a double click the image of the checkbox changes twice (as for two clicks) while the state of the checkbox changes only once => incoherent behavior. Besides there's not much code to show, it's basically the default behavior of the component... BTW I'm using Vista. – gregseth Mar 16 '11 at 08:39
  • When I double-click a node's checkbox, the image (with "image" I mean the checkbox flag) and the node checked-state change both only once, so I can't reproduce the problem... perhaps it's OK on XP :( – digEmAll Mar 16 '11 at 08:55
  • Yes, I confirm it, it works fine on XP while in Win 7 I have the same problem as you... – digEmAll Mar 17 '11 at 12:49
  • It may be related to the .NET framework shipped with the OS... do you know which one you used for your tests? – gregseth Mar 18 '11 at 07:34
  • I used .net 3.5. Anyway, the problem is definitely on the OS because I used the same executable on both OS and on xp was OK while on W7 the issue appeared... – digEmAll Mar 19 '11 at 15:16

1 Answers1

5

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);
        }
    }
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
Varsha
  • 66
  • 1