Hi there,
i've found the trail of the FlyTreeView Component for .NET 2.0 by searching for an alternative for the obout TreeView and at this moment i'm tryring to populate the Tree with my exsiting DataSet.
I've got the folowing colums:
Node_id, Parent_id, Description, TreeName, NodeLevel, Expanded, classTable, class_id.
The important for rendering are Node_id, Parent_id, Desc and NodeLevel.
I think they are all selfspeaking, except the NodeLevel, it is a int value that determinate the position in the Tree, 0 = root, 1,2,3 ...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
' Create sample data
Dim dSet As New DataSet_test
Dim myadapter As New DataSet_testTableAdapters.V_TreeDataTableAdapter
Dim mytable As DataSet_test.V_TreeDataDataTable = myadapter.GetData()
Dim dTable As New DataSet_test.V_TreeDataDataTable
dSet.Tables.Add(dTable)
dTable.Rows.Add(New Object() {0, 0, \"root\", \"\", 0, False, \"folder.gif\", \"\", 1})
Dim i As Integer = 0
For i = 0 To mytable.Rows.Count - 1
'' Add nodes (OwnerID is null for root nodes)
Response.Write(mytable.Rows(i).Item(0).ToString() + \"
\")
If mytable.Rows(i).Item(1).Equals(DBNull.Value) Then
dTable.Rows.Add(New Object() {mytable.Rows(i).Item(0), 0, mytable.Rows(i).Item(2).ToString(), \"\", 0, False, \"folder.gif\", \"\", 1})
Else
dTable.Rows.Add(New Object() {mytable.Rows(i).Item(0), mytable.Rows(i).Item(1), mytable.Rows(i).Item(2).ToString(), \"\", 0, False, \"folder.gif\", \"\", 1})
'
End If
Next
Dim j As Integer = 0
For j = 0 To (dTable.Rows.Count - 1)
Response.Write(dTable.Rows(j).Item(0).ToString() + \" - \" + dTable.Rows(j).Item(1).ToString() + \" - \" + dTable.Rows(j).Item(2).ToString() + \"
\")
Next
' Call FlyTreeView.ConvertTabularDataToHierarchical method to convert into hierarchical datasource
Try
Dim hierarchicalData As IHierarchicalEnumerable = NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(dTable, \"Node_id\", \"Parent_id\", \"Parent_id\")
' Bind the treeview
flyTreeView.DataSource = hierarchicalData
flyTreeView.DataBind()
Catch ex As Exception
Response.Write(ex.ToString())
End Try
End If
End Sub
With this code i'm trying to populate the Tree, as base i've used the default VB.NEt Project and the Demo_DataBinding_Tabular.aspx file from the examples.
This is the output i've got
1
2
3
4
5
6
7
8
0 - 0 - root
1 - 0 - Personal
2 - 1 - test1
3 - 1 - test2
4 - 1 - test3
5 - 0 - Verwaltung
6 - 5 - Buro
7 - 5 - Kantine
8 - 5 - Keller
System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) at NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(Object dataSource, String dataMember, String keyFieldName, String parentKeyFieldName) at Demo_DataBinding_Tabular.Page_Load(Object sender, EventArgs e) in C:\\Program Files\\9Rays.Net\\FlyTreeView for ASP.NET 2.0\\samples\\vb\\Demo_DataBinding_Tabular.aspx.vb:line 50
dose someone know why i allways get this damn error?! The given tabular Data \"dTable\" seems to be correct...
thx an regard,
martin