Solved

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

Posted on 2006-06-30
4
301 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 69

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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Setting runtime form location 4 29
Getting multiple values from a dataset ASP.NET(VB) 3 37
Help with Query not working in client's PC 1 35
Help with LINQ and XML 10 25
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now