Negative parent ID on nodes

4 posts, 0 answers
  1. Sonya L
    Sonya L avatar
    36 posts
    Member since:
    Dec 2009

    Posted 17 May 2011 Link to this post

    I have a treeview bound to a binding list, and I have noticed that when I add items to the binding list with a negative number (other than -1) as the parent ID, the treeview control clears out and shows just that node.  Does anyone know why this might be happening?  Thanks!
  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 20 May 2011 Link to this post

    Hello Sonya L,

    Thank you for contacting us.

    In this case you should use numeric properties for ID and ParentID. When using a DataTable, you can change the column type. Please consider the following example:

    DataTable table = new DataTable();
    table.Columns.Add("Id", typeof(int));
    table.Columns.Add("ParentId", typeof(int));
    table.Columns.Add("Name");
     
    table.Rows.Add(0, -1, "Root1");
    table.Rows.Add(1, -1, "Root2");
    table.Rows.Add(2, -1, "Root3");
     
    table.Rows.Add(3, 0, "Child1");
    table.Rows.Add(4, 1, "Child2");
    table.Rows.Add(5, 2, "Child3");
     
    radTreeView1.DataSource = table;
    radTreeView1.ParentMember = "ParentId";
    radTreeView1.ChildMember = "Id";
    radTreeView1.DisplayMember = "Name";

    I hope it helps. Should you have any further questions, do not hesitate to ask.

    Kind regards,
    Julian Benkov
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sonya L
    Sonya L avatar
    36 posts
    Member since:
    Dec 2009

    Posted 24 May 2011 Link to this post

    I was looking for a solution that allowed the ParentID to be a negative number other than -1, so that if I had a node whose ID was -101, it could have children whose parent ID was -101.  Since this doesn't work in bound mode (a lot of other things don't work in bound mode either), I had to rewrite my code to build the tree without binding it to data.  If the tree is not bound, this no longer is a problem.
  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 27 May 2011 Link to this post

    Hello Sonya L,

    I logged the issue in our Issue Tracking System. The fix will be available in the next official release.
    Currently, to work properly in this scenario, the ParentID number for all root Nodes must have the same number. For example, this can be a '-101' or '-1'. 

    Greetings,
    Julian Benkov
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Back to Top