Self-referencing freeze

3 posts, 0 answers
  1. Grzegorz
    Grzegorz avatar
    5 posts
    Member since:
    Feb 2013

    Posted 22 May 2013 Link to this post

    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. Grzegorz
    Grzegorz avatar
    5 posts
    Member since:
    Feb 2013

    Posted 22 May 2013 Link to this post

    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.
  3. Peter
    Admin
    Peter avatar
    1157 posts

    Posted 27 May 2013 Link to this post

    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?
Back to Top