Solved

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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