Double-click event for TreeView control

zhaozj2021-02-16  180

Author: (ZJH135 Zhang Jun-hong)

This example implements double-click node, popup dialog and displays node information

First add some data on TreeView1, the code is as follows:

SUB EXAMPLE ()

DIM N As New Treenode, I as Integer, J AS Integer

For i = 0 TO 3

WITH N.NODES.ADD ((i * 15) .tostring & "-" & ((i 1) * 15 - 1) .tostring)

For j = 0 to 14

.NODES.ADD ((J i * 15) .tostring)

NEXT

End with

NEXT

Dim Nodetoadd as Treenode

For i = 1 to 24

Nodetoadd = n.clone

Nodetoadd.text = i.totring

TreeView1.nodes.Add (NodeToadd)

NEXT

End Sub

Add the following code in the TreeView1_Click event:

Dim n as treenode = ctype (sender, windows.forms.treeview) .selectedNode

'// If the tree node is not 0, the prompt information is displayed.

IF n.GetnodeCount (false) = 0 THEN

'// Text characters of the current node

DIM S as string = n.text

'// If the character length is 1, then add 0

If s.ley = 1 THEN

S = s.insert (0, "0") '// Specify location inserted into characters

END IF

'// Character plus the current node character in a tree node

S = n.parent.text & ":" & s

'// Of course, you can also display the characters of the higher level node

'// code changes to: s = n.parent.parent.text & ":" & S

Messagebox.show ("The character you choose is:" & s)

END IF

转载请注明原文地址:https://www.9cbs.com/read-7762.html

New Post(0)