?
Solved

Several Treeview-Questions...

Posted on 2005-04-02
7
Medium Priority
?
235 Views
Last Modified: 2010-04-23
Hello

I am using the Treeview-Control for my first time and I have some questions...
I have now the following Treeview:

http://www.ruttensoft.com/file/treeview.jpg

The questions:

1. How can I select "Name von eigenem Projekt" without using the mouse?
2. How can I make a new Item at "My Company"?  (at the selected item)?
3. How can I rename the selected item in the treeview itself?
4. How can I delete the selected item?

Thanks a lot in advance

Sven
0
Comment
Question by:Dumdidum
  • 5
  • 2
7 Comments
 
LVL 12

Accepted Solution

by:
S-Twilley earned 400 total points
ID: 13688480
Ok... i think these 4 functions cover the lot:

-----------------------------------------------------------------------
    Function SelectNodeOnText(ByVal NodeText As String, ByVal TopNode As Object) As Boolean
        TreeView1.SelectedNode = Nothing

        Dim thisNode As TreeNode
        For Each thisNode In TopNode.Nodes
            If thisNode.Text.ToLower = NodeText.ToLower Then
                TreeView1.SelectedNode = thisNode
                Return True
            Else
                If SelectNodeOnText(NodeText, thisNode) Then Return True
            End If
        Next
        Return False
    End Function

-----------------------------------------------------------------------
    Function AddToSelectedNode(ByVal NodeText As String) As TreeNode
        If TreeView1.SelectedNode Is Nothing Then
            Return Nothing
        Else
            Return TreeView1.SelectedNode.Nodes.Add(NodeText)
        End If
    End Function

-----------------------------------------------------------------------
    Function RenameSelectedNode(ByVal NodeText As String) As Boolean
        If TreeView1.SelectedNode Is Nothing Then
            Return False
        Else
            TreeView1.SelectedNode.Text = NodeText
            Return True
        End If
    End Function

-----------------------------------------------------------------------
    Function RemoveSelectedNode() As Boolean
        If TreeView1.SelectedNode Is Nothing Then
            Return False
        Else
            TreeView1.Nodes.Remove(TreeView1.SelectedNode)
            Return True
        End If
    End Function

=================================

The first function (with your example text) you'd call using:

         SelectNodeOnText("Name von eigenem Projekt", TreeView1)


If you want me to explain the rest of the functions, just say
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13688490
Notes:


X = AddToSelectedNode("BLAH BLAH")   ' where X is declared as a treenode
           If a node is selected, a node with text "BLAH BLAH" is added, and a reference to that new node is returned
           If no node is selected, then Nothing is returned

           If you don't need a reference to the newly added node, remove the "X = " from the code line

Y = RenameSelectedNode("BLAH BLAH")  ' where Y is declared as a boolean
           If a node is selected, it's text is changed to "BLAH BLAH".. and True is returned to express a success
           If no node is selected, then False is returned to express failure

           If you don't need to know whether it was a success or not, remove the "Y = "

Z = RenameSelectedNode()  ' where Z is declared as a boolean
           If a node is selected, it is removed (including it's child nodes).. and True is returned to express a success
           If no node is selected, then False is returned to express failure

           If you don't need to know whether it was a success or not, remove the "Z = "
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13688491
sorry, that last code line was supposed to read:

Z = RemoveSelectedNode()  ' where Z is declared as a boolean
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Dumdidum
ID: 13688516
Hi

Thanks, is it possible to rename the selected note directy in the treeview?

Like this:

http://www.ruttensoft.com/file/tree.jpg

Thanks

Sven
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13688540
Not sure I understand you...  to edit a label/node like that, you set LabelEdit (property of treeview) to true...  select the node you want to edit, then click on it once.

... if you want to start the label edit through code:

   Function EditSelectedNode() As Boolean
        If TreeView1.SelectedNode Is Nothing Then
            Return False
        Else
            TreeView1.SelectedNode.BeginEdit()
            Return True
        End If
    End Function

NOTE:  Make sure the TreeView's LabelEdit property is set to true before you try to use the above
0
 

Author Comment

by:Dumdidum
ID: 13688583
Thanks, one last question:

Is it possible to copy one treeview to another?

Thanks

Sven
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13688602
Not really... you can't add an existing node into another treeview control (if you try it, you'll get an error).

I think you'd have to go through all the nodes making clones (or copies with the same properties so you're not actually using that node) of them.

I could be wrong tho.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

621 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