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

AddSelfReference Same Table

2 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 27 Jul 2013, 01:53 PM

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 Answers, 1 is accepted

Sort by
0
Peter
Top achievements
Rank 1
answered on 27 Jul 2013, 02:37 PM
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?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 31 Jul 2013, 04:59 PM
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 >>
Tags
GridView
Asked by
Peter
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or