|
-
Jul 12th, 2007, 08:19 AM
#1
Thread Starter
Addicted Member
[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
-
Jul 12th, 2007, 12:03 PM
#2
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.
-
Jul 12th, 2007, 12:57 PM
#3
Thread Starter
Addicted Member
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
-
Jul 12th, 2007, 07:30 PM
#4
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
-
Jul 13th, 2007, 08:25 AM
#5
Thread Starter
Addicted Member
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
-
Jul 13th, 2007, 10:19 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|