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.
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
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:
myDataGrid.DataSource = myTreeNode.Tag
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
Quote:
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
Re: [02/03] Open DataTable
This doesn't make sense:
Quote:
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:
Quote:
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.