Where can I find the Click event in the tree nodes?
I have a problem with treeview I cannot find a way to find the click event in each child node
Here's an example image
here's what I've tried so far.
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
If TreeView1.SelectedNode.Level = 0 Then
MsgBox("1")
ElseIf TreeView1.SelectedNode.Level = 1 Then
MsgBox("2")
ElseIf TreeView1.SelectedNode.Level = 2 Then
MsgBox("3")
ElseIf TreeView1.SelectedNode.Level = 3 Then
MsgBox("4")
ElseIf TreeView1.SelectedNode.Level = 4 Then
MsgBox("5")
End If
End Sub
The problem is every child layer node in the message field it always says 2
+3
source to share
1 answer
The event you are using is a good event. If you want to get the new selected node, just use the object EventArgs
in the event handler (parameter named e
). The following code is C #, not VB.Net, but it's very simple:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
// Use the e parameter to get the new selected node
MessageBox.Show(e.Node.Text);
}
+5
source to share