Results 1 to 6 of 6

Thread: [02/03] Open DataTable

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    200

    [02/03] Open DataTable

    Hi,


    I have been trying to do something similar, but haven't seem to get it to work. I have read many posts that does similar functions as what I am trying to accomplish. I have tried their approach but it will not display the selected datatable inside of a datagrid because I am confused on the following:

    1: How would I be able to display the appropriate data inside of the datatable in a DataGrid based on the value that the user select.

    I am able to figure out what node the user has double-clicked. But I need help with displaying the data for the selected datatable.


    Here is the code which I have for obtaining the value of the node that the user has selected. Any help would be greatly appreciated. thanks
    I am using [VB.NET 2003]

    Code:
       Private Sub TreeView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DoubleClick
            Dim Node_Value As Integer
    
            'Loop through the entire range and select the 
            For i As Integer = 0 To 10
                If (TreeView1.SelectedNode.Text = i) Then
    
                    '
                    Node_Value = TreeView1.SelectedNode.Text
    
                End If
            Next
    
            '''''''
            '''''''
            '''''''Now display the appropriate datatable that is inside of the Database
            '''''''
            '''''''
    
        End Sub

    Any help is greatly appreciated. thanks

    -Srig

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [02/03] Open DataTable

    Supposed that you want to pull up the data from your database that matches the value of the doubled-clicked treenode (whatever that is -- it looks like an integer from your code). So in the event handler subroutine, you will build your select statement based on the node value and run the query to fill a datatable, then bind that datatable to your datagird...
    You can write a function that accepts the selected value and returns a datatable and call it in the event handler sub.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    200

    Re: [02/03] Open DataTable

    But from the code that I have, I already obtain the correct treenode that the user has selected using the double_click event. Now I need to figure out the proper query syntax to grab the data from the correct datatable.

    I dont think I need to use a case statement to select the correct datatable if I already know what datatable the user is requesting. The problem I have is how to bind the datatable to the Selected Node.

    Cant I do somethind like this:

    Code:
    For Each drv As DataRow In DataSet11.Tables(Node_Value).Rows            
      
                'Display the information from NAME Field            
                 Debug.Print(drv("Radius").ToString)            
                'Display the information from STATUS Field            
                 Debug.Print(drv("Degree").ToString)    
    
    Next

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Open DataTable

    Are you saying that you already have the populated DataTables? If so then just assign them to the Tag property of the nodes. Displaying the appropriate data is then as easy as:
    vb.net Code:
    1. myDataGrid.DataSource = myTreeNode.Tag
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    200

    Re: [02/03] Open DataTable

    jmcilhinney, thanks for your reply. I do have the datatable populated inside of the Access database. I am confused on what you just mentioned. Can you please explain what you meant by
    assign them to the Tag property of the nodes
    .

    Here is what I did, but it doesn't make any sense to me, and it gives me an error.

    Code:
        Private Sub TreeView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DoubleClick
            Dim Selected_Node As Integer
    
            'Loop through the entire range and select the 
            For i As Integer = 0 To 10
                If (TreeView1.SelectedNode.Text = i) Then
    
                    '
                    Selected_Node = TreeView1.SelectedNode.Text
    
                End If
            Next
    
    
            DataGrid1.DataSource = Selected_Node
    End Sub

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Open DataTable

    This doesn't make sense:
    I do have the datatable populated inside of the Access database.
    Like all databases, Access databases contain tables. DataTables are .NET objects though. There are no DataTables in Access. You retrieve data from your access database and you populate DataTables in your VB.NET code with that data. My question was: have you already retrieved the data from the database and populated the DataTables, or are you doing that when the user selects a node?

    As for this:
    assign them to the Tag property of the nodes
    you've got DataTables and you've got TreeNodes. There's a 1:1 correspondence between them. Assign each DataTable to the Tag property of the corresponding TreeNode. Then when the user selects a node you simply get the table for its Tag, exactly as I showed.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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