Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't there a SelectedNodeChanged event for Windows.Forms.TreeView?

The System.Web.UI.WebControls.TreeView class offers this event, but the Forms version of TreeView doesn't. What's the equivalent in the Forms world? I'm using AfterSelect but it doesn't seem quite right. Maybe it is in fact what I'm looking for but the documentation is a bit hazy.

like image 903
I. J. Kennedy Avatar asked Nov 04 '09 01:11

I. J. Kennedy


People also ask

How do I know if TreeView node is selected?

Solution 1Use TreeView. SelectedNode[^] property, which get or set selected node for currently selected Treeview. If no TreeNode is currently selected, the SelectedNode property is a null reference (Nothing in Visual Basic).

How do you edit TreeView?

The TreeView allows you to edit nodes by setting the allowEditing property to true. To directly edit the nodes in place, double click the TreeView node or select the node and press F2 key. When editing is completed by focus out or by pressing the Enter key, the modified node's text saves automatically.


1 Answers

There's none in WinForms TreeView. To quote MSDN for TreeView.AfterSelect:

This event does not occur when the node is unselected. To detect this occurrence, handle the Control.MouseUp event and test the TreeNode.IsSelected property.

Yes, this sucks.

like image 51
Pavel Minaev Avatar answered Oct 11 '22 03:10

Pavel Minaev