edrz01
asked on
Dynamically add nodes to treeview from query pulling data from MS Access
I am using vb 2003 and MS Access 2000.
I need to, when a button is clicked, run a query to pull data from an Access table and populate a treeview with those values.
I already have the dataset working (I can go into preview data). The returned data is system hostnames and is called "hostname".
I would like the treeview to look like
-Server1
-Server2
-Server3
.....
I hope to reuse this type of thing if I could figure out how to add a node to a treeview as a result of a query.
Help!
I need to, when a button is clicked, run a query to pull data from an Access table and populate a treeview with those values.
I already have the dataset working (I can go into preview data). The returned data is system hostnames and is called "hostname".
I would like the treeview to look like
-Server1
-Server2
-Server3
.....
I hope to reuse this type of thing if I could figure out how to add a node to a treeview as a result of a query.
Help!
ASKER
Eric,
Thanks for the response. I looked at your code and tried to incorporate it into mine but I am getting an error.
This is my code snippet:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ds As New DataSet
Me.OdbcDataAdapter1.Fill(d s, "HostName")
With tvServers
.BeginUpdate()
.Nodes.Clear()
For Each drCat As DataRow In DsServerList1.Tables("host name").Row s <<<<<<< Error here
Dim nodParent As TreeNode
nodParent = tvServers.Nodes.Add(drCat. Item("host Name").ToS tring)
Next drCat
.ExpandAll()
.EndUpdate()
.Nodes(0).EnsureVisible()
End With
End Sub
-------------------------- --
The error I am getting in on the line indicated above by the <<<<<
An unhandled exception of type 'System.NullReferenceExcep tion' occurred
Any thoughts?
Thanks for the response. I looked at your code and tried to incorporate it into mine but I am getting an error.
This is my code snippet:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ds As New DataSet
Me.OdbcDataAdapter1.Fill(d
With tvServers
.BeginUpdate()
.Nodes.Clear()
For Each drCat As DataRow In DsServerList1.Tables("host
Dim nodParent As TreeNode
nodParent = tvServers.Nodes.Add(drCat.
Next drCat
.ExpandAll()
.EndUpdate()
.Nodes(0).EnsureVisible()
End With
End Sub
--------------------------
The error I am getting in on the line indicated above by the <<<<<
An unhandled exception of type 'System.NullReferenceExcep
Any thoughts?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well, so it is. My oversight! You are a genius. Thank you, thank you, thank you - it worked!
See an article I wrote in April 2006 at http://emoreau.s2i.com/
Cheers!