Anyone know, how to change the value by typing and new value in the treeview?
Printable View
Anyone know, how to change the value by typing and new value in the treeview?
vb Code:
Private Sub Form_Load() TreeView1.Nodes.Add , , "A", "A" TreeView1.Nodes.Add , , "B", "B" TreeView1.Nodes.Add , , "C", "C" TreeView1.Nodes.Add "A", tvwChild, "A1", "A1" TreeView1.Nodes.Add "A", tvwChild, "A2", "A2" TreeView1.Nodes.Add "B", tvwChild, "B1", "B1" TreeView1.Nodes.Add "B", tvwChild, "B2", "B2" End Sub Private Sub Command1_Click() Dim tNode As Node Set tNode = TreeView1.Nodes("A1") tNode.Text = "A1A" tNode.Key = "A1A" End Sub
How Can I typing the Value in the treeview?
that is a default action.
selcted the node... then click again. you can change it
if the list is being saved, then make sure you save the new text
you can user StartLabelEdit Method to do this
Quote:
Originally Posted by MSDN
Code:Private Sub Form_Load()
Dim nodX As Node
Dim i As Integer
TreeView1.LabelEdit = tvwManual ' Set property to manual.
Set nodX = TreeView1.Nodes.Add(,,," Node 1") ' Add first node.
For i = 1 to 5 ' Add 5 nodes.
Set nodX = TreeView1.Nodes.Add(i,tvwChild,,"Node " & CStr(i + 1))
Next I
nodX.EnsureVisible ' Show all nodes.
End Sub
Private Sub Command1_Click()
' Invoke the StartLabelEdit method on the selected node,
' which triggers the BeforeLabelEdit event.
TreeView1.StartLabelEdit
End Sub
Private Sub TreeView_BeforeLabelEdit (Cancel as Integer)
' If the selected item is the root, then cancel the edit.
If TreeView1.SelectedItem Is TreeView1.SelectedItem.Root Then
Cancel = True
End If
End Sub
Private Sub TreeView_AfterLabelEdit _
(Cancel As Integer, NewString As String)
' Assume user has entered some text and pressed the ENTER key.
' Any nonempty string will be valid.
If Len(NewString) = 0 Then
Cancel = True
End If
End Sub
Inseead of a Command Button, you can use a Popup Menu to do this
eg:
Code:Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then PopupMenu mnuPopupMaster
End Sub
Private Sub mnuRenameLabel_Click()
TreeView1.StartLabelEdit
End Sub
:wave:
Thank you both of you.
I would like to know.. After I change the value to the new value. How I can use the update value?
use the AfterLabelEdit event
eg
:wave:Code:Private Sub TreeView1_AfterLabelEdit(Cancel As Integer, NewString As String)
If MsgBox("Change to " & NewString & "?", vbOKCancel) = vbOK Then
Cancel = 0
Else
Cancel = 1
End If
End Sub