AddSelfReference Same Table

3 posts, 0 answers
  1. Peter
    Peter avatar
    4 posts
    Member since:
    Apr 2013

    Posted 27 Jul 2013 Link to this post


    Hi All

    I have a simple question regarding hierarchical data.

    I have one table which I return as a data reader.

    id (int)    desc (varchar)    parentid (int)
    1            desc 1                NULL
    2            desc 2                1    
    3            desc 3                2
    4            desc 4                NULL
    5            desc 5                4

    This table is self-referencing, i.e. linked list

    I know the tree view can handle this relationship automatically

    how can I implement this into the grid? can anyone give me a simple example?

    I simply tried

    this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "id", "parentid");


    but it doesn't show any results in the table.

    Thanks
    Peter


  2. Peter
    Peter avatar
    4 posts
    Member since:
    Apr 2013

    Posted 27 Jul 2013 Link to this post

    Update:

    got it to display by setting the following:


                    radGridView1.MasterTemplate.AutoGenerateColumns = true;

    I guess I cannot manually add columns as per the code below when doing the self reference?

                    this.radGridView1.Columns.Add(new GridViewTextBoxColumn("My ID"));
                    this.radGridView1.Columns["My ID"].FieldName = "id";

    Or can I do it a different way?

  3. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3907 posts

    Posted 31 Jul 2013 Link to this post

    Hello Peter,

    Thank you for contacting Telerik Support.

    You have found out the correct solution for displaying the data. For a detailed example about Self-Referencing Hierarchy in RadGridView please have a look at the following help article

    It is possible to add manually columns to your grid (please see the attached picture):
    this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "Id", "ParentFolderId");
    this.radGridView1.DataSource = list;
     
    this.radGridView1.Columns.Add(new GridViewTextBoxColumn("My ID"));
    this.radGridView1.Columns["My ID"].FieldName = "Id";

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top