?
Solved

Several Treeview-Questions...

Posted on 2005-04-02
7
Medium Priority
?
228 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
[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
  • 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
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!

 

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

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 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