Results 1 to 3 of 3

Thread: Add Child Nodes to Treeview dynamically

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    257

    Add Child Nodes to Treeview dynamically

    Hello,

    I have the following code which checks for the value of the 'cc_supplier_status' column for each of the rows in my table. If the state is 0, I need a child node to be added to a node named 'Inactive Suppliers' in my tree view (tvw_Supplier) with it's text being the value of the 'cc_supplier_name' value for the same row.

    If the state is 1, a child node is to be added to a node named 'Active Suppliers'.

    If the state is 2, a child node is to be added to a node named 'Pending Suppliers'.

    The code I have now just filters out the status value for each row, and performs a select case on it. I need to know how I'd add a new child node to the parent nodes mentioned above.


    Code:
            Dim totalRows As Integer = Me.CCSuppliersDataSet.tblSuppliers.Rows().Count()
    
            Dim counter As Integer
            For Each row As CCSuppliersDataSet.tblSuppliersRow In Me.CCSuppliersDataSet.tblSuppliers.Rows()
    
                Dim name As String = row.cc_supplier_name.ToString()
                Dim status As Integer = row.cc_supplier_status()
                Select Case status
                    Case 0
                        ' Add a node who's text is the value of 'name' to the 
                        ' Inactive Suppliers node
    
                    Case 1
                        ' Add a node who's text is the value of 'name' to the 
                        ' Active Suppliers node
    
                    Case 2
                        ' Add a node who's text is the value of 'name' to the 
                        ' Pending Suppliers node
    
                End Select
    
                counter = counter + 1
    
                Dim percentage As Integer = CInt((counter / totalRows) * 100)
                Me.bgwk_Supplier_Nodes.ReportProgress(percentage)
    
            Next

    Thanks.
    Last edited by r000t; Aug 24th, 2011 at 09:02 AM.

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Add Child Nodes to Treeview dynamically

    Add the three parent nodes, but keep a reference to them. In your for loop and select case, access the Nodes property of the appropriate parent node and add another node. You can add the nodes via the Add method.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    257

    Re: Add Child Nodes to Treeview dynamically

    Quote Originally Posted by ForumAccount View Post
    Add the three parent nodes, but keep a reference to them. In your for loop and select case, access the Nodes property of the appropriate parent node and add another node. You can add the nodes via the Add method.
    Hello,

    The parent nodes have already been added in the designer.

    The problem I have is adding the nodes within a background worker. I'm thinking I'm going to need the Invoke() method, as I'm adding nodes in a different thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width