Question

I've got a TreeList that's basically like a Photoshop layers palette. It's a hierarchical list with checkboxes to toggle visibility of a document's individual layers. This is done via the BeforeChecked event, which is raised right before the .Checked value toggles.

It works fine, except if you double-click it, at which point it all seems to go haywire.

If you double-click a checkbox once, it toggles the checked value twice (which is the intended behavior), but it doesn't toggle the visibility of the layer twice because it doesn't raise the BeforeChecked twice.

I figured I'd get around this by putting this in the MouseDoubleClick event:

TreeViewHitTestInfo hit = treeLayerPalette.HitTest(e.X, e.Y);
hit.Node.Checked = !(hit.Node.Checked);

This works for all double-clicks except for the first one. So it only raises the BeforeChecked event once (and not the MouseDoubleClick) at first, getting the checkbox out of sync with the visibility of the layer, and then all following double-clicks raise both the BeforeChecked and MouseDoubleClick events (which in turn raises the BeforeChecked event), maintaining that incorrect relationship.

Also, at one point, I put a MessageBox.Show() in the DoubleClick event. Awkwardly enough, it does not actually get shown on a double-click, but instead gets shown on a third click, no matter how much time has elapsed between the actual double-click and the third click. A third click performed 20 seconds after a double-click will raise the MouseDoubleClick event, but the actual double-click won't.

What's actually going on here, and how can I fix it?

Was it helpful?

Solution

this is a problem with Checkbox Enabled treeviews, however there are a few acceptable workrounds.. Firstly: MS know about the problem but refuse to fix it... : http://connect.microsoft.com/VisualStudio/feedback/details/775922/treeview-double-click-bug#details <-- The Bug report....

So there is no way but to workaround it.. simplest been to subclass the Treeview and forcibly disable the dblclick on the checkbox... answer (on SOF) : c# treeview ignore double click only at checkbox

Hope this helps....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top