|
-
Dec 14th, 2010, 11:44 AM
#1
Thread Starter
New Member
Treeview Duplicates
I'm new to VB.NET (VB6 programmer) and from the various threads i've searched, I have put together the code below to catch duplicates in order to populate a treeview. I'm after the following result:
Audi
- A4
- A5
BMW
- 1 Series
- 3 Series
My data is simply two columns: Audi, A4, Audi, A5, BMW, 1 Series, etc...
Code below:
'-----------------------------------------------------------------
Dim parentrow As DataRow
Dim ParentTable As DataTable
ParentTable = ds.Tables("Makes")
Dim parentnode As TreeNode
Dim lastName As String
lastName = ""
For Each parentrow In ParentTable.Rows
For Each row As DataRow In ParentTable.Rows
If CStr(row("Manufacturer")) <> lastName Then
parentnode = New TreeNode(parentrow.Item(0))
Else
parentnode.Nodes.Add(parentrow.Item(1))
End If
lastName = CStr(row("Manufacturer"))
Next
Next
'----------------------------------------------------------------
Unfortunately the parentnode in the Else part of the code is showing "variable used before assigned". Any help with the above would be appreciated.
Thanks in advance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|