Solved

Adding to the Treeview

Posted on 2011-03-19
6
912 Views
Last Modified: 2012-08-14
I'm writing a vb.net application that will use the treeview control to display info to the users.  It works to add a node to the first level nodes, but when trying to add a node to the second level nodes, it adds a node but it has no information assigned to it.  The way I add a node to the tree is I create a tree node, then assign information to it, then add it to the tree.  I've displayed a message box with information about the treenode and all information is there before its added.  My code basically works this way below:

Get info for node0

Treeview.nodes.add(node0)

Get info for node1

Treeview.nodes(node0).nodes.add(node1)

Get info for node2

Treeview.nodes(node0).nodes(node1).nodes.add(node2)

Node2 doesn't get added correctly. All information is correct in Node2 and something does get added to the tree but with no information.  Has anyone had this problem before?  Thanks for any help.
0
Comment
Question by:rcblevins
  • 2
  • 2
  • 2
6 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35171943
have you tried to keep a reference to the node you just added:

mynode0 = Treeview.nodes.add(node0)
mynode1 = mynode0.nodes.add(node1)
mynode1.nodes.add(node2)
0
 
LVL 12

Expert Comment

by:omegaomega
ID: 35172307
Hello, rcblevins,

I'm not sure what you mean by "information", but as far as I know Nodes requires an integer index, so an expression like:

    Treeview.nodes(node0).nodes.add(node1)

should cause an error.  If you can show the actual code that you are using to populate the TreeView we may be able to provide more help.

Cheers,
Randy


0
 

Author Comment

by:rcblevins
ID: 35172373
Here is the code.  The problem is where node2 is being used.  The stn node has information in it when its added to the tree, but the tree shows that a blank node is added.  The other wierd thing is that I also tried to show the name of the node refereced by node1 which should be node2's parent and it's name comes back empty.  Thanks for your help.

Dim node0 As Integer
        Dim node1 As Integer
        Dim node2 As Integer
        Dim node3 As Integer
        Dim node4 As Integer


        TreeView.Nodes.Clear()

        TreeView.BeginUpdate()

              Dim mddr As SqlDataReader

            mddr = Get Data

            If (mddr.HasRows) Then

                While (mddr.Read())


                    Dim mdtn As New TreeNode


                    mdtn.Tag = mddr.GetInt32(0)
                    mdtn.Text = mddr.GetString(1)
                    mdtn.ToolTipText = mddr.GetInt32(0).ToString

                    node0 = TreeView.Nodes.Add(mdtn)

                    Dim cdr = Get Data

                    If (cdr.HasRows) Then

                        While cdr.Read()

                            Dim ctn As New TreeNode

                            ctn.Tag = cdr.GetInt32(0)
                            ctn.Text = cdr.GetString(1)
                            ctn.ToolTipText = cdr.GetInt32(0).ToString


                            node1 = TreeView.Nodes(node0).Nodes.Add(ctn)


                                Dim sdr = Get Data

                                If (sdr.HasRows) Then

                                    While sdr.Read()

                                        Dim stn As New TreeNode

                                        stn.Tag = sdr.GetString(0)
                                        stn.Name = sdr.GetString(1)


                                        node2 = TreeView.Nodes(node0).Nodes(node1).Nodes.Add(stn)

                                   End While

                                End If

                                sdr.Close()

                            End If

                        End While

                    End If

                    cdr.Close()

                End While


            End If

            mddr.Close()


        End If

        TreeView.EndUpdate()
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 69

Expert Comment

by:Éric Moreau
ID: 35172452
>>node1 = TreeView.Nodes(node0).Nodes.Add(ctn)

node1 cannot be an integer. you have mixed your variables. see how I fill a treeview at http://www.emoreau.com/Entries/Articles/2006/04/The-Treeview-control.aspx
0
 
LVL 12

Accepted Solution

by:
omegaomega earned 500 total points
ID: 35172508
Hello, rcblevins,

I think that you just are missing a line that reads:

    stn.Text = ...

Cheers,
Randy
0
 

Author Comment

by:rcblevins
ID: 35172662
Lol!  I had looked and looked over that code.  I was thinking in the back of my mind that is was something simple.  I just needed someone else to see it I guess.  Thanks for the help.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Retain selection in datagridview 2 22
Combobox, SelectedIndexChanged Get Index 2 22
Getfiles in vb.net 28 18
Open a word document 23 13
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

16 Experts available now in Live!

Get 1:1 Help Now