?
Solved

VB Tree question

Posted on 2002-04-11
5
Medium Priority
?
156 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 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
            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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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