In self-reference if you bind the grid to a record having is ParentId the same as its Id, the grid will try to create a row which is parented by itself. This is not valid input data and we should throw a proper exception, otherwise the application will freeze.
How to reproduce:
public partial class Form2 : Form
{
private BindingList<DataObject> data;
public Form2()
{
InitializeComponent();
this.radGridView1.AutoGenerateHierarchy = true;
this.data = new BindingList<DataObject>();
int count = 10;
for (int i = 0; i < count; i++)
{
DataObject p = new DataObject();
p.Id = i;
p.Name = "Parent " + i;
this.data.Add(p);
for (int j = 0; j < count; j++)
{
DataObject c = new DataObject();
c.Id = count + j + i * count;
c.Name = "Child " + i;
c.ParentId = i;
this.data.Add(c);
}
}
this.radButton1.Click += RadButton1_Click;
}
private void RadButton1_Click(object sender, EventArgs e)
{
if (this.radGridView1.Relations.Count > 0)
{
this.radGridView1.Relations.Clear();
}
this.radGridView1.DataSource = this.data;
this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "Id", "ParentId");
}
}
public class DataObject
{
public int Id { get; set; }
public string Name { get; set; }
public int ParentId { get; set; }
}
Workaround: set the ParentId of the parent records
int count = 10;
for (int i = 0; i < count; i++)
{
DataObject p = new DataObject();
p.Id = i;
p.Name = "Parent " + i;
p.ParentId = -1;
this.data.Add(p);
for (int j = 0; j < count; j++)
{
DataObject c = new DataObject();
c.Id = count + j + i * count;
c.Name = "Child " + i;
c.ParentId = i;
this.data.Add(c);
}
}