Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


VB Tree question

Posted on 2002-04-11
Medium Priority
Last Modified: 2010-08-05
I have a two level tree:
           element 1.0.1

How can I imitate windows explorer of renaming a selected node. Displaying kind of text box over it and give an option to the user rename the node. then when clicked on the tree get rid of that kind of text box. If question is not that clear, go to win explorer, right click, rename. Thanks for your expert matters.

Question by:nesifa
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6934066
With the treeview control, you can have the Labeledit mode to Automatic ?!

To start the edit by code:

LVL 43

Accepted Solution

TimCottee earned 120 total points
ID: 6934096
Private Sub Form_Load()

    With TreeView1
        .LabelEdit = tvwManual
        For i = 1 To 3
            Set tvnNew = TreeView1.Nodes.Add(, , "Item " & i, "Item " & i)
            tvnNew.Expanded = True
            For j = 1 To 3
                Set tvnSub = TreeView1.Nodes.Add(tvnNew, tvwChild, "Item " & i & ", " & j, "Item " & i & ", " & j)
                tvnSub.Expanded = True
    End With
End Sub

Private Sub Rename_Click()
End Sub

Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = vbRightButton Then
        PopupMenu Popup
    End If
End Sub

You need to create a Menu for the form, with the appropriate functions, one of which is Rename then you will get the functionality you need.

Author Comment

ID: 6934143
still it does not work. assume that this is happening on doubleclick event. I see no actions. could be more specific. thanks.
LVL 43

Expert Comment

ID: 6934238
Then you would have the same but code in that event:

Private Sub TreeView1_DoubleClick()
   If Button = vbRightButton Then
       PopupMenu Popup
   End If
End Sub

Or at the most simple:

Private Sub TreeView1_DoubleClick()
End Sub
LVL 18

Expert Comment

ID: 6934442
Generally, you should not do this edit action on a double-click.  The double-click is commonly reserved for "launching" things.  With the treeview control, if you have set the property to allow label edits, then if the user clicks on the label and holds down the mouse long enough, the label will go into edit mode.  Or, you can provide a popup menu if the user right-clicks that has a menu item for rename or edit, and then put the label into edit mode manually through the code.  This is consistent with Windows Explorer, and you shouldn't change the way that works.

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question