473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Loading a dataset in VB.net after selecting record from TreeView

I am new to VB.net so I am not sure if there is a good way to do this or not but here is my problem. I have created a form with a TreeView control on it. When the user selects a node from the treeview I would like to use the AFTER_SELECT method to bring up a new form if possible containing a dataset for the record selected. OR as an alternative I would like to bring up a dataset for that record selected on the same form. I have succeeding in capturing the node selected (e.node.text) however I can't use that variable to load the data set using an SQL statement or can I?????. Is there any easy way to do this????

Here is a sample of my code:
thanks in advance

Dim qryString1 As String = "SELECT * FROM ClientTab WHERE CLNAME LIKE '" & Selectnode & "%'"



Private Sub PopulateTreeView(ByVal inParentID As Integer, ByRef inTreeNode As TreeNode)
objConn.Open()
myReader = objCmd.ExecuteReader

' Dim Reader As OleDb.OleDbDataReader = objCmd.ExecuteReader()
While myReader.Read
For Columns = 0 To myReader.FieldCount - 1
Category = myReader.Item(Columns)
Next
On Error Resume Next
Parentnode = "Client"
Childnode = Split(Category, "")(0)
If Childnode = Nothing Then
TreeView1.Nodes.Add(Parentnode)
'LastNodeSet = Parentnode
LastNodeSet = Childnode
NodeRootRow += 1
Else
If Parentnode = LastNodeSet Then
TreeView1.Nodes(NodeRootRow).Nodes.Add(Childnode). ToString()
Else
TreeView1.Nodes.Add(Parentnode).Nodes.Add(Childnod e).ToString()
'TreeView1.Nodes.Add(Childnode).Nodes.Add(Childnod e).ToString()
LastNodeSet = Parentnode
NodeRootRow += 1
End If
End If
Parentnode = Nothing : Childnode = Nothing
End While

myReader.Close()
objConn.Close()

End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim pnode = "Client"
Dim Selectnode As String

Selectnode = e.Node.Text
If e.Node.Text <> pnode Then
objConn.Open()
OLDAdapter.Fill(AHSCLIENTFILEDataSet)
objConn.Close()
' Dim F3 As New Form3
' Dim childform As New Form3
' childform = New Form3()
' F3.MdiParent = Me
' childform.Show()
End If
End Sub
Oct 15 '07 #1
2 4037
Shashi Sadasivan
1,435 Expert 1GB
You can set an sql statememnt to the table adapters and send in parameters.

Please search online for examples on how to do this. (it a fairly common task)

Once you have the sql statement ready, pass the text value to this statement to get the resulting dataset

cheers
Oct 15 '07 #2
Thanks so much Shashi! You pointed me in the right direction and I was able to find an example that did what I needed to do.

Basically all I needed to do was add a new query to my dataset and then I added the following code to my TreeView1_After_Select

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim pnode = "Client"
Dim Selectnode = e.Node.Text
If e.Node.Text <> pnode Then
MessageBox.Show(Selectnode)
CLIENTABLE2TableAdapter.Fill(Me.AHSCLIENT2DataSet. CLIENTABLE2, Selectnode)
End If
Oct 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Gidi | last post by:
Hello, i writing a application in C#, i have dataGrid that connect to DataSet and DataAdapter that takes data from my sql dataBase, the problem is that the form is loaded very very slow, i heared...
1
by: http://www.visual-basic-data-mining.net/forum | last post by:
Hello, I am working on Treeview control. I want that, user create tree according to his requirement, can add topic under any node. Then just click update and that treeview data to be stored in...
4
by: CMW | last post by:
In VB.NET I'm retrieving a single table from a SQL Server (tblformdata). I need to search each record in the dataset to see if any data is missing from the records (i.e., missing first name,...
4
by: Fred Nelson | last post by:
I have an applicatioin that I'm writing that uses a "case" file that contains over 350 columns and more may be added in the future. I would like to create a dataset with all the column names and...
2
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView...
0
by: Jeremiah Harbottle | last post by:
Hi, Using VC to write a small app that displays data extracted from a database into a typed DataSet. That all works fine. I have three tables - Parent, Child, and then each record in the Child...
3
by: P K | last post by:
Hello, I have a dataset which is already loaded with data in one table. so dataset.tables("data") exists and has data. Now, I have to add another table to the dataset. The source for this...
1
by: Medes | last post by:
Hi, I am trying to load my items from Database to a Treeview but i have faild My table contains id, parentId, nodeName like following: (1 , 1 RootNode) (2 , 2 , ParentNode)
1
by: vbDavidC | last post by:
I am adding a new record to a table via a dataset/adapter. I have got the following to work for me but I am wondering if there is a better way to do this. I am having to have something in my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.