Solved

VB Tree question

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now