Update Row Height Programmatically

Hi,

I have a SFDataGrid, I want my rows to be Height of 50 to start. I have a column that is a switch and once switched I want that row to grow to 100 height.

I've got it wired up to a way that I think will work, but the row doesn't grow immediately, it requires I scroll it out of view and back into view before it will then again look to update the height to 100. How can I force fire the QueryRow height without requiring me to scroll the item off screen then back on again? I tried accessing the SfDataGrid.RowCollection but it seems to be empty.

Here's what my code looks like, I'm keeping a dictionary to know which items need to have height 100.

    private void datagrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e) {
            if (PCDictionary.ContainsKey(e.RowIndex)) {
                e.Height = PCDictionary[e.RowIndex];
            }
            else if (e.Height == 50) {
                //do nothing
            }
            else {
                e.Height = 50;
            }
            e.Handled = true;
        }

1 Reply

VR Vigneshkumar Ramasamy Syncfusion Team September 28, 2018 10:49 AM UTC

 
Thanks for contacting Syncfusion support. 
 
We have anyalyzed your requirement of “change row height at run time when switch column is swiched” and it can be achieved by using ValueChanged and QueryRowHeight event in SfDataGrid control and InvalidateRowHeight method which triggers the QueryRowHeight event for the specific row.  
 
Please find the below code snippet in which InvalidateRowHeight method is called to trigger QueryRowHeight if switch column is changed. 
 
  private void DataGrid_ValueChanged(object sender, Syncfusion.SfDataGrid.XForms.ValueChangedEventArgs e) 
        { 
            if (e.Column.MappingName == "IsClosed") 
                dataGrid.InvalidateRowHeight(e.RowColumnIndex.RowIndex, true); 
        } 
 
        private void DataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e) 
        { 
            var record = this.dataGrid.GetRecordAtRowIndex(e.RowIndex); 
            if (record != null && (record as OrderInfo).IsClosed) 
            { 
                e.Height = 100; 
            } 
            else 
            { 
                e.Height = 50; 
            } 
            e.Handled = true; 
        } 
 
 
 
Sample link: SwitchColumn
 
 
Please let us know if this help full. 
 
Regards 
Vigneshkumar R 


Loader.
Up arrow icon