jgore
asked on
TreeView - Rename Node
I want a routine like in Exporer where it renames a Node
using a little box around the Node name. Can this be done in VB6?
You know what I mean, if your in Exporer and choose a directory
you can right-click, get a menu, choose Rename and it will
put a little box around the directory name and let you enter new text!
I can bring up the right-click menu but what now!
How do I put a little box around TreeView Node and retype name?
using a little box around the Node name. Can this be done in VB6?
You know what I mean, if your in Exporer and choose a directory
you can right-click, get a menu, choose Rename and it will
put a little box around the directory name and let you enter new text!
I can bring up the right-click menu but what now!
How do I put a little box around TreeView Node and retype name?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both of you!
You fixed me right up.
Cya'z.............
You fixed me right up.
Cya'z.............
--------------------------
The following procedure can be used to edit the node name on the TreeView side of the Windows Explorer:
Click on a node with focus to place it in edit mode.
Remove all the text from the Node label.
Move focus to a different Node.
You receive the following error message: You must type in a file name.
Focus returns to the Node you were editing and you remain in edit mode.
If you hit the Esc Key, the original text is placed back in the Node label.
MORE INFORMATION
This sample demonstrates how to achieve the same effect using the TreeView control in Visual Basic. It also shows how to verify that when a user edits a Node label that it is not left blank.
Step-by-Step Example
Create a new standard EXE project. Form1 is created by default.
From the Project menu, select Components, check "Microsoft Windows Common Controls 6.0," and then click OK.
Add a TreeView and Timer control to Form1.
Add the following to the code window of Form1:
Option Explicit
Dim sNodeText As String ' to hold the node text
Private Sub Form_Load()
'Add some nodes to the TreeView
TreeView1.Nodes.Add , , , "test"
TreeView1.Nodes.Add , , , "test 1"
TreeView1.Nodes.Add , , , "test 2"
End Sub
Private Sub Timer1_Timer()
' Put the TreeView in edit mode
TreeView1.StartLabelEdit
Timer1.Enabled = False
End Sub
Private Sub TreeView1_AfterLabelEdit(C
NewString As String)
' Make sure that we have a value in the Label
If Len(NewString) < 1 Then
' The Label is empty
MsgBox "Error! You must enter a value"
' enable the Timer to get us back to edit mode
Timer1.Interval = 100
Timer1.Enabled = True
End If
End Sub
Private Sub TreeView1_BeforeLabelEdit(
' If the label is not empty store the string
If Len(TreeView1.SelectedItem
sNodeText = TreeView1.SelectedItem.Tex
End If
End Sub
Private Sub TreeView1_KeyUp(KeyCode As Integer, Shift As Integer)
' If the user hits the Esc key then restore the old label
If KeyCode = vbKeyEscape Then
TreeView1.SelectedItem.Tex
End If
End Sub
Save and run the project. Click on a Node to select it, then click on it again to place it in edit mode.
Follow steps 1-7 as described in the Summary above. When you hit the ESC key, you will see that the old value for the Node label has been restored.