lo_oscar
asked on
Treeviewitem and for loop
I have a legacy code I'm maintaining that uses a for loop to bind data rows from a dataset into a tree view for wpf. A request came in to add a root node to the existing 2 level tree view. I'm not familiar on how to assign child nodes in treeview control and a few attempts so far has been unsuccessful.
The data in the table should look like below:
TABNAME TYPEDESC EVENTDATE VIEWPARMS
A ABC MM/DD/YYYY 1234567
A ABC MM/DD/YYYY 2164546
A DEF MM/DD/YYYY 1546546
B GHI MM/DD/YYYY 6548484
I want to use for loop to add a root node for TABNAME so the treeview will have 3 tiers instead of 2:
TABNAME
|_ TYPEDESC
|_ EVENTDATE TYPEDESC
For Each iRow In iDataSet.Tables("Table1").Rows
If iRow("TABNAME") <> PreviousTab Then
Dim oTreeNodeTabName As New TreeViewItem
oTreeNodeTabName.Header = iRow("TABNAME")
oTreeNodeTabName.Tag = Nothing
_TreeView.Items.Add(oTreeNodeTabName)
End If
If iRow("TYPEDESC") <> PreviousDesc Then
Dim oTreeNodeHeader As New TreeViewItem
oTreeNodeHeader.Header = iRow("TYPEDESC")
oTreeNodeHeader.Tag = Nothing
count += 1
_TreeView.items.Add(oTreeNodeHeader)
End If
Dim oTreeNode As New TreeViewItem
oTreeNode.Header = iRow("EVENTDATE") & " " & iRow("TYPEDESC")
oTreeNode.Tag = iRow("VIEWPARMS")
Dim tvItem As TreeViewItem = _TreeView.Items(count)
tvItem.Items.Add(oTreeNode)
The data in the table should look like below:
TABNAME TYPEDESC EVENTDATE VIEWPARMS
A ABC MM/DD/YYYY 1234567
A ABC MM/DD/YYYY 2164546
A DEF MM/DD/YYYY 1546546
B GHI MM/DD/YYYY 6548484
I want to use for loop to add a root node for TABNAME so the treeview will have 3 tiers instead of 2:
TABNAME
|_ TYPEDESC
|_ EVENTDATE TYPEDESC
ASKER
Thanks. I have try this too but are getting an error
"Element already has a logical parent. It must be detached from the old parent before it is attached to the new one."
This happens when the second oTreeNodeChild is added while I run debug.
"Element already has a logical parent. It must be detached from the old parent before it is attached to the new one."
This happens when the second oTreeNodeChild is added while I run debug.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for the explanation. It was spot on.
Open in new window