I have a SfDataGrid, usually data is single line, but there are some rows that can have multiple lines. However it seems the line height is being set by first line and multiline text getting trimmed. How can I make SfDataGrid to auto set the height of every row.
I'm using version 18.4.0.30.
Thank you.
I use QueryRowHeight event now but it still trims some of cell content, like 2 or 3 pixels. Also it ruins the Row Header, I specified the HeaderRowHeight but it seems to be ignoring it now.
GridRowSizingOptions gridRowResizingOptions = new GridRowSizingOptions();
//To get the calculated height from GetAutoRowHeight method.
double autoHeight;
this.dataGrid.QueryRowHeight += dataGrid_QueryRowHeight;
void dataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
if (this.dataGrid.GridColumnSizer.GetAutoRowHeight(e.RowIndex, gridRowResizingOptions, out autoHeight))
{
if (autoHeight > 24)
{
e.Height = autoHeight;
e.Handled = true;
}
}
}
Okay if I add following code, the header is back to normal.
if (e.RowIndex == 0)
return;
Turn out, the Row 0 is header, thats not good idea.
how do I get Row's source object inside QueryRowHeight
Hi John,
You can get the Row Data (ie. Source object of the Row) inside the QueryRowHeight event by using the RowIndex.
|
//Here I have used the row source object as EmployeeInfo which is getting from record entry.Data.
var recordEntry = this.sfDataGrid.View.Records[e.RowIndex] as RecordEntry; if (recordEntry != null && recordEntry.Data != null) { var contactNumber = (recordEntry.Data as EmployeeInfo).ContactNumber; } |
Sample: https://www.syncfusion.com/downloads/support/forum/171888/ze/DataGridDemo-217476072.zip
Regards,
Sathiyathanam
okay but there is another problem the dataGrid.GridColumnSizer.GetAutoRowHeight() always outputs same value for all rows
Edit :
Following error on var recordEntry = this.sfDataGrid.View.Records[e.RowIndex] as RecordEntry;
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'
Are you aware, row index 0 is row header ?
Edit 2 :
Even the DataGrid "AutoRowHeightDemo" doesn't work properly, to test, open that demo and change the combobox value to something longer value and you will see the selected value getting trimmed.