Solved

Dynamically add nodes to treeview from query pulling data from MS Access

Posted on 2006-06-30
4
316 Views
Last Modified: 2010-05-18
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!
0
Comment
Question by:edrz01
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 17019636
Hi edrz01,

See an article I wrote in April 2006 at http://emoreau.s2i.com/

Cheers!
0
 

Author Comment

by:edrz01
ID: 17019776
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(ds, "HostName")

        With tvServers
            .BeginUpdate()
            .Nodes.Clear()
            For Each drCat As DataRow In DsServerList1.Tables("hostname").Rows        <<<<<<< Error here
                Dim nodParent As TreeNode
                nodParent = tvServers.Nodes.Add(drCat.Item("hostName").ToString)
            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.NullReferenceException' occurred

Any thoughts?
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 125 total points
ID: 17019831
isn't your dataset called ds ?

Change this line:
For Each drCat As DataRow In DsServerList1.Tables("hostname").Rows        

for that one:
For Each drCat As DataRow In ds.Tables("hostname").Rows        
0
 

Author Comment

by:edrz01
ID: 17019858
Well, so it is. My oversight! You are a genius. Thank you, thank you, thank you - it worked!

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 48
VB.NET 1 28
VB.Net - Get ColumnNames of SQL Table 4 15
Expression Evaluater 3 37
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question