Home - Forums-.NET - FlyTreeView (ASP.NET) - Problem populating Tree by DataSet

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Problem populating Tree by DataSet
Link Posted: 15-Nov-2006 01:17
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
Link Posted: 15-Nov-2006 03:05
Your code:
NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(dTable, \"Node_id\", \"Parent_id\", \"Parent_id\")


Probably should not use dataMember parameter since you're passing table:
NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(dTable, null, \"Node_id\", \"Parent_id\")

or better:
NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(dTable, \"Node_id\", \"Parent_id\")
Link Posted: 14-Jun-2011 05:55
I changed the code to:

Dim hierarchicalData As IHierarchicalEnumerable = NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(DSet, "NodeID", "NodePARENT")

The flytreeview now says System.data.DataRowView
Link Posted: 14-Jun-2011 07:42
the combination of node bindings and the above fix to code works now
Link Posted: 09-Jun-2011 06:25
I'm trying to use a dataset. I'm trying to use code from an earlier version of your product. My code:

Dim DSet As New Data.DataSet("DataBase")
        Dim DTable As New Data.DataTable("TREE")

SQL = "SELECT        NodeID, NodePARENT, NodeHTML " & _
            "FROM            LOOKUP_Tree " & _
            "WHERE        (ASOF = '" & ASOF & "')  AND (NodeID > 1)" & _
            "ORDER BY NodeSORT"

        MyConnection = New Data.SqlClient.SqlConnection(ConnectionString)
        Dim MyCommand As Data.SqlClient.SqlDataAdapter
        MyCommand = New Data.SqlClient.SqlDataAdapter(SQL, MyConnection)
        TREE1 = New System.Data.DataSet()
        MyCommand.Fill(TREE1, "TREE_INFO")

        DSet.Tables.Add(DTable)
        DTable.Columns.Add("NodeID")
        DTable.Columns.Add("NodePARENT")
        DTable.Columns.Add("NodeHTML")
        DTable.Columns.Add("Selected")
        DTable.Rows.Add(New Object() {1, Nothing, "MFO", True})

        For Each row As Data.DataRow In TREE1.Tables(0).Rows
            Dim arr() As Object = row.ItemArray()
            NodeID = arr(0)
            NodePARENT = arr(1)
            NodeHTML = arr(2)
            DTable.Rows.Add(New Object() {NodeID, NodePARENT, NodeHTML})
        Next

        Dim hierarchicalData As IHierarchicalEnumerable = NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(DSet, "TREE", "NodeID", "NodePARENT")

        FlyTreeView1.DataSource = hierarchicalData
        FlyTreeView1.DataBind()

I've added a gridview to the page to list the elements in DSet and all the records are there. The flytree view element on the aspx page lists only system.Data.DataRowView and no data.
Link Posted: 09-Jun-2011 06:33
Do you have node bindings defined likes it is done in the example:
http://www.9rays.net/asp.net_2/treeview/Demo_DataBinding_Tabular.aspx