Solved

VB Tree question

Posted on 2002-04-11
5
150 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

808 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