Performing a treeview treenode click from code.

G

Guest

Hello

I am writing an application in VB.NET that utilizes a treeview. I want to allow my users to add new nodes to the treeview

In my code, I dimension a treenode and set the tree node text to "Type New Process Category Name.

I then set the treeview LabelEdit property to True and call the BeginEdit method

Everything works fine, but before the user can edit the treenode data, he or she must first click on the treenode to activate the edit mode

How can I provide this click event for my customer, so he or she does not have to click on the node first. I would like my customer to just begin typing without requiring them to click on the node. Is this possible

A snippet of my code is below. I appreciate any feedback or suggestions

Best regards

Ma

Dim intSelectedTreeNode As Integer = -
Dim tn As New TreeNod
tn.Text = "Type New Process Category Name
If Me.trePCM_Process.SelectedNode Is Nothing The
Me.trePCM_Process.Nodes.Insert(0, tn
Els
intSelectedTreeNode = Me.trePCM_Process.SelectedNode.Inde
Me.trePCM_Process.Nodes.Insert((intSelectedTreeNode + 1), tn
End I
'-- Now select the newly inserted node
Me.trePCM_Process.SelectedNode = t
Me.trePCM_Process.LabelEdit = Tru
If Not Me.trePCM_Process.SelectedNode.IsEditing The
Me.trePCM_Process.SelectedNode.BeginEdit()
 
P

Peter Huang

Hi Max,


I have tried your code as below.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TreeView1.Nodes.Add("First Node")
TreeView1.Nodes.Add("Second Node")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim intSelectedTreeNode As Integer = -1
Dim tn As New TreeNode
tn.Text = "Type New Process Category Name"
If Me.TreeView1.SelectedNode Is Nothing Then
Me.TreeView1.Nodes.Insert(0, tn)
Else
intSelectedTreeNode = Me.TreeView1.SelectedNode.Index
Me.TreeView1.Nodes.Insert((intSelectedTreeNode + 1), tn)
End If
'-- Now select the newly inserted node.
Me.TreeView1.SelectedNode = tn
Me.TreeView1.LabelEdit = True
If Not Me.TreeView1.SelectedNode.IsEditing Then
Me.TreeView1.SelectedNode.BeginEdit()
End If
End Sub


After I click the button1, the selected node has entered the edit mode. We
do not need to select the node again.

If I misunderstanding you meaning, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top