Solved

VB Tree question

Posted on 2002-04-11
5
151 Views
Last Modified: 2010-08-05
Hi,
I have a two level tree:
 element1.0
           element 1.0.1
  element2.0
           element2.0.1
           element2.0.2

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.

Nesifa
0
Comment
Question by:nesifa
[X]
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
5 Comments
 
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:
TreeView1.StartLabelEdit

CHeers
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 30 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
            Next
        Next
    End With
End Sub

Private Sub Rename_Click()
    TreeView1.StartLabelEdit
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.
0
 

Author Comment

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

Expert Comment

by:TimCottee
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()
  TreeView1.StartLabelEdit
End Sub
0
 
LVL 18

Expert Comment

by:mdougan
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

733 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