Grid row details -- how to get base row data object for details row?

Posted by: a.sharov on 17 August 2022, 12:31 pm EST

    • Post Options:
    • Link

    Posted 17 August 2022, 12:31 pm EST - Updated 3 October 2022, 10:15 pm EST

    Hi.

    I have grid with row details, I need proper way to access parent row data object, so I could make proper query based on it’s fields.

    Previously, I’ve used setup method:

    
              public override void Setup(C1FlexGrid parentGrid, int rowIndex)
              {
                  base.Setup(parentGrid, rowIndex);
    
                  var bs = parentGrid.DataSource as BindingSource;
                  var obj = bs.Current as SomeObj;
                  //query based on obj.Id                 
                  //setup child grid datasource
                  C1FlexGrid.OwnerDrawCell += C1FlexGridOnOwnerDrawCell;
    
              }
    
    

    But it seems to be wrong (buggy) becuase I relied on a fact that when I expand cell (click on cross, see img) then datasource raw will be selected accrodingly, but seems not to be the case. So, suppose that initially I select first row and then try to expand other rows details, then according to code above I would query data based on selected first row id, which is clearly wrong (wrong id).

    So, to make this approach work correctly I need first explicitly select raw and then expand cell (cross sign), I think this is very poor user experience .

    I 've tried to use followng approach:

    
      var ht = intervalGrid.HitTest();
    
                    if (ht.Type == HitTestTypeEnum.Cell || ht.Type == HitTestTypeEnum.RowHeader)
                    {
                        var mi = grid.Rows[ht.Row].DataSource as DataObj;
                        Debug.Assert(mi != null, nameof(mi) + " != null");
                        return new M DetailRowContainer(mi.Id);
                    }
    
                    return null;
    
    

    More or less it works until one start scrolling where things start working simply randomly, I mean I saw cases where after scroll child grid had data of another parent row.

    So, the question is what is a correct approach for a child row to get it’s parent row ?

    
    grid.RowDetailProvider = (g, r) =>
                {
                     //TODO code here to get correct parent row
                       return new DetailRowContainer();
                 };
    
    

    Thanks in advance.

  • Posted 17 August 2022, 2:06 pm EST

    Is this a correct and robust approach? (seems to be, btw):

     
    grid.RowDetailProvider = (g, r) =>
                {
                    var adjIndex = r - grid.Rows.Fixed; //especailly this part!
                    var mi = grid.Rows[adjIndex].DataSource as DataObject;
                    Debug.Assert(mi != null, nameof(mi) + " != null");
                    return new DetailRowContainer(mi.Id);
                };
    

    I really didn’t pay attention to r-parameter till I realized that my first approch via

    
       var bs = parentGrid.DataSource as BindingSource;
        var obj = bs.Current as SomeObj;
    
    

    doesn’t work as expected.

    Also, please, can you explain why scrolling triggers creation of a detail grid every time? Grid rerenders itself and fires appropriate event for already opened detail grids?

    This means that each time it goes to db (in my case), can I prevent it?

  • Posted 18 August 2022, 5:28 am EST

    Hi,

    The best approach to get the index of the parent row is to use the r parameter of the method assigned to the RowDetailProvider delegate. You can also get the parent row index in the Setup method, using its rowIndex parameter.

    Also, we are getting in touch with the development team to get more information regarding the RowDetail setting up each time when scrolling. We will update you as soon as possible.

    [Internal tracking ID: C1WIN-28028]

    Thanks, and Best Regards,

    Kartik

  • Posted 18 August 2022, 9:43 am EST

    Thank you for reply, Kartik.

    Meanwhile, is this correct approach to get row real index

    var adjIndex = r - grid.Rows.Fixed; 
    

    ?

  • Posted 19 August 2022, 3:42 am EST

    Hi,

    If you want to get the index of the parent rows in the Grid, you can use the above approach.

    If you want to directly get the index of the underlying DataSource of the Row, you can also use the DataIndex property of the Row.

    c1FlexGrid1.Rows[r].DataIndex
    

    Please see the attached video showing the same. DataIndex.zip

    Best Regards,

    Kartik

  • Posted 22 August 2022, 8:34 am EST

    Hi,

    As per the development team, the RowDetail object for the expanded row is removed when scrolled out of the view due to the economy of the resources of the application as each control is a window, which has its own handle and the number of handles is limited per application. Therefore, disabling this behavior is not directly possible.

    Although, you can implement a cache of RowDetails objects (on the first setup create it and store it inside a container, eg. Dictionary), and the next time just find the needed control in the collection and return it for use.

    Using this approach, you can restrict the Setup method code to run only once for a RowDetail. Kindly refer to the attached sample showing a simple implementation of the same.

    RowDetail_Fg.zip

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels