We help IT Professionals succeed at work.

Dynamcally populating a TreeView

Could someone tell me what's wrong with my code?

im trying to do what the title of the post says.....

However, on the line

Dim row As New Data.DataRow

I get the following error

'System.Data.DataRow.Protected Sub New(builder As System.Data.DataRowBuilder)' is not accessible in this context because it is 'Protected'.      

What's wrong? How do I declare a row??


Private Sub FillCustomers(ByVal parent As TreeNode)
        Dim conn As New SqlConnection("Data Source=DAODEVBOX;Initial Catalog=suds_prototype;User ID=sa;Password=***")
        Dim ds As New Data.DataSet()
        Dim da As New SqlDataAdapter("select * from Categories", conn)
        da.Fill(ds, "Category")
        Dim row As New Data.DataRow
        For Each row In ds.Tables("Category").Rows
            Dim node As TreeNode = New TreeNode()
            node.Text = row("companyname").ToString()
            node.Value = row("customerid").ToString()
            node.PopulateOnDemand = True
            node.SelectAction = TreeNodeSelectAction.SelectExpand
    End Sub

Open in new window

Watch Question

dont use New in your Row-declaration,

Dim row as Data.DataRow

because you are getting the row instance in the loop, and declaring it with new needs parameters.


arggh! ok great thank you....

Explore More ContentExplore courses, solutions, and other research materials related to this topic.