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

Self-referencing freeze

2 Answers 77 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Grzegorz
Top achievements
Rank 1
Grzegorz asked on 22 May 2013, 09:12 AM
I'm facing strange self-referencing grid behaviour. Symptoms:
1) All rows (even without children) contains "+"
2) Expanding parent row cause freeze without any exception thrown.

Object:
public class MyObject
{
    public long Id {get; set;}
    public string Name {get; set;}
    public string Code {get; set;}
    public MyObject Parent {get;set;}
}

Grid contains columns for Code and Name defined in designer.
Than I'm adding self reference:
GridViewTextBoxColumn col1 = new GridViewTextBoxColumn("Id", "Id");
GridViewTextBoxColumn col2 = new GridViewTextBoxColumn("ParentId", "Parent.Id");
grid.MasterTemplate.Columns.Add(col1);
grid.MasterTemplate.Columns.Add(col2);
  
grid.Columns["Id"].IsVisible = false;
grid.Columns["ParentId"].IsVisible = false;
grid.Relations.AddSelfReference(grid.MasterTemplate, "Id", "ParentId");

And data populating:
private void Populate(IList<MyObject> dataToPopulate)
 {
    this.grid.BeginUpdate();
    var relationsBackup = this.grid.Relations.ToList();
    this.grid.Relations.Clear();
    this.grid.DataSource = dataToPopulate;
    this.grid.Relations.AddRange(relationsBackup);
    this.grid.EndUpdate();
    this.grid.MasterView.Refresh();          
 }



Thank for any suggestion in advance.

2 Answers, 1 is accepted

Sort by
0
Grzegorz
Top achievements
Rank 1
answered on 22 May 2013, 04:48 PM
I finally found the reason.
I appeared that data mocked for test where incorrect. All objects had the same Id therefore there was circular reference in grid.

It would be good, it self-referencing mechanism would check if parent value is different than child and throw exception instead of freezing in loop.
0
Peter
Telerik team
answered on 27 May 2013, 07:53 AM
Hello Greg,

I am happy that you found what causes this.

We are not able to provide such a mechanism for checking for the correct self-reference, because this is considered related to the business logic and not to the UI. In this regard, it would be the developer who should check if the data is correct. If the UI component is to take care of this, this would result in a slow performing component.

Should you have any other questions, do not hesitate to ask.

Regards,
Peter
Telerik
RadChart for WinForms is obsolete. Now what?
Tags
GridView
Asked by
Grzegorz
Top achievements
Rank 1
Answers by
Grzegorz
Top achievements
Rank 1
Peter
Telerik team
Share this question
or