This is a migrated thread and some comments may be shown as answers.

Tree From Self-Referencing Data

8 Answers 330 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Jim Holmes
Top achievements
Rank 1
Jim Holmes asked on 03 Jul 2007, 10:55 AM

I'm having problems getting self-referencing data to display in my RadTreeView.  I'm using the Q1 2007 release in VS Team Suite SP1 on Vista 32bit.

I'm trying to bind the tree to a DataSet which holds the following Xml data:
<Toc>
  <Node>
    <Title>Main Title</Title>
    <Target>d03.xml</Target>
    <id>1</id>
    <parentId>-1</parentId>
  </Node>
  <Node>
    <Title>Child Title</Title>
    <Target>d0300000.xml</Target>
    <id>2</id>
    <parentId>1</parentId>
  </Node>
</Toc>

When using the Property Builder and selecting the DataSet as the DataSource, "Toc" as the DataMember, and Toc.Title as the DisplayMember then I get no items at all shown in the resulting WinForm.

When setting properties in code as below I get the title of the two nodes; however, no graphics or parent/child relationship are shown.

dataSet1 = new DataSet();
dataSet1.ReadXml("d03_toc.xml");
radTreeView1.DataSource = dataSet1;
radTreeView1.DataMember = "Toc";
radTreeView1.DisplayMember = "Toc.Title";
radTreeView1.ValueMember = "Toc.id";
radTreeView1.ParentIDMember = "Toc.parentId";

It's completely unclear in the help file if or how I'm supposed to use the Property Builder to create any nodes when using a bound data source.  Is this part of my problem?

I'd certainly appreciate a pointer as to where I've gone wrong.

8 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 03 Jul 2007, 04:07 PM
Hi Jim,

To load an xml file into a DataSet, it must be in the right format. Here is a code snippet which shows the proper format:
 
<TocDataSet> 
  <Toc> 
      <Title>Main Title</Title> 
      <Target>d03.xml</Target> 
      <id>1</id> 
      <parentId>-1</parentId> 
  </Toc> 
  <Toc> 
      <Title>Child Title</Title> 
      <Target>d0300000.xml</Target> 
      <id>2</id> 
      <parentId>1</parentId> 
  </Toc> 
</TocDataSet> 


Also in the schema of the DataSet, the type for the id, and parentId fields must be set to int:

DataSet dataSet1 = new DataSet();  
DataTable tocTable = new DataTable("Toc");  
tocTable.Columns.Add("Title"typeof(string));  
tocTable.Columns.Add("Target"typeof(string));  
tocTable.Columns.Add("id"typeof(int));  
tocTable.Columns.Add("parentId"typeof(int));  
dataSet1.Tables.Add(tocTable); 

Now you can set the data binding properties:

radTreeView1.DataMember = "Toc";  
radTreeView1.DisplayMember = "Title";  
radTreeView1.ValueMember = "id";  
radTreeView1.ParentIDMember = "parentId";  
radTreeView1.DataSource = dataSet1; 


And voila, you have node and a child node :)

As for the Property Builder, the current design time support needs some improvements and we will be happy if you share your ideas with us. Currently, you cannot mix data binding and design time created nodes.

To add nodes to a bound tree you must modify the data source as follows:

DataRow row = tocTable.NewRow();  
row["Title"] = "New node";  
row["Target"] = "target";  
row["id"] = 3;  
row["parentId"] = 2;  
tocTable.Rows.Add(row); 

We will be vary happy if you share any ideas, suggestions, needs, etc. regarding RadTreeView data binding and help us improve it.

 
All the best,
Jordan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jim Holmes
Top achievements
Rank 1
answered on 05 Jul 2007, 02:18 PM
Thanks for the help. 

Just so I'm clear: Was there really a need to change my initial XML structure?  As far as I can tell the only substantial part missing was specifically configuring the DataSet with a matching schema.

I think documentation updates covering this material would be greatly helpful.  Unless I missed it, there was no mention of setting a schema, or more specifically ensuring that the ID and ParentID value fields must be of type int.  Clarification on whether or not node configuration is needed would be helpful.  I also think you should put a specific note at the top of the databinding section that you can't mix databinding and design time property manipulation.

I'm happy with the control so far and I understand it's an early release, but the documentation needs more guidance/clarification.

Thanks again!
0
Jordan
Telerik team
answered on 06 Jul 2007, 02:05 PM
Thank you for the feedback, Jim! We are planning a major update of the documentation for the Q2 release and we will surely take your notes into account. Improved docs are on our agenda and we are confident that your work will be easier after the Q2 release.

As to the XML, if you provide the correct schema there is no need to change the file.

Again, thank you for your suggestions.


Greetings,
Jordan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Dogu
Top achievements
Rank 1
answered on 11 Mar 2008, 11:16 AM
hi,

I am using 2007q3 winforms.
In treeview I experienced a problem. with self referencing databound i experienced problem with checkboxes. Treeview control does not display checkboxes starting from level 3. Am I doing something wrong ?

dogu tumerdem
0
Martin Vasilev
Telerik team
answered on 11 Mar 2008, 06:07 PM
Hi dogu.tumerdem,

Please find the answer to your question in the other topic you have created about this issue. 
 

Kind regards,
Martin Vasilev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Paul Yerre
Top achievements
Rank 1
answered on 19 Mar 2010, 11:48 AM
Using the self-referencing mode with RadTree which works fine..but how do i change the format of a node depending on some data.  WHat event should i be using?   I assume something like databound or similar?
0
Victor
Telerik team
answered on 24 Mar 2010, 04:51 PM
Hello Paul Yerre,

Thank you for the question.

Currently the only way to do this is the CollectionChanged event of the Nodes collection but it is feasible only for root level nodes. If you want to be notified for nodes deeper in the hierarchy you will have to devise a mechanism to dynamically subscribe to the Nodes collections of added nodes.

We will provide an event that will make this easier in a future release.

Greetings,
Victor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Noah
Top achievements
Rank 1
answered on 22 Jul 2011, 06:44 AM
Cancel that.... I didn't notice the ChildMember Property that goes along with the ParentMember property. 8)

I have tried to follow your example here for using a radtreeview on a self references table.  But now that I have moved up from  2010.3.10.1215 version of the RadControls for WinForms to the 2011.1.11.419 I have not been able to get this working.

I have even tried to create a new project with just a RadTreeview on it, but with no success.
Any help you may have with this would be greatly appreciated.

I am using the following code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim DataSet1 As System.Data.DataSet
        Dim DataTable1 As System.Data.DataTable
        Dim DataColumn1 As System.Data.DataColumn
        Dim DataColumn2 As System.Data.DataColumn
        Dim DataColumn3 As System.Data.DataColumn
 
        DataSet1 = New System.Data.DataSet()
        DataTable1 = New System.Data.DataTable()
        DataColumn1 = New System.Data.DataColumn()
        DataColumn2 = New System.Data.DataColumn()
        DataColumn3 = New System.Data.DataColumn()
 
        '
        'DataSet1
        '
        DataSet1.DataSetName = "NewDataSet"
        DataSet1.Tables.AddRange(New System.Data.DataTable() {DataTable1})
        '
        'DataTable1
        '
        DataTable1.Columns.AddRange(New System.Data.DataColumn() {DataColumn1, DataColumn2, DataColumn3})
        DataTable1.TableName = "Table1"
        '
        'DataColumn1
        '
        DataColumn1.ColumnName = "ID"
        DataColumn1.DataType = GetType(Integer)
        '
        'DataColumn2
        '
        DataColumn2.ColumnName = "ParentID"
        DataColumn2.DataType = GetType(Integer)
        '
        'DataColumn3
        '
        DataColumn3.ColumnName = "Display"
 
        Dim Row As DataRow = DataTable1.NewRow()
        Row.Item("ID") = 0
        Row.Item("ParentID") = DBNull.Value
        Row.Item("Display") = "First"
        DataTable1.Rows.Add(Row)
 
        Row = DataTable1.NewRow()
        Row.Item("ID") = 1
        Row.Item("ParentID") = DBNull.Value
        Row.Item("Display") = "Second"
        DataTable1.Rows.Add(Row)
 
        Row = DataTable1.NewRow()
        Row.Item("ID") = 2
        Row.Item("ParentID") = 0
        Row.Item("Display") = "half"
        DataTable1.Rows.Add(Row)
 
 
        Me.RadTreeView1.DisplayMember = "Display"
        Me.RadTreeView1.ValueMember = "ID"
        Me.RadTreeView1.ParentMember = "ParentID"
 
        Me.RadTreeView1.DataSource = DataTable1
    End Sub
Tags
Treeview
Asked by
Jim Holmes
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Jim Holmes
Top achievements
Rank 1
Dogu
Top achievements
Rank 1
Martin Vasilev
Telerik team
Paul Yerre
Top achievements
Rank 1
Victor
Telerik team
Noah
Top achievements
Rank 1
Share this question
or