//Hooks QueryRowHeight event in SfDataGrid to set the row height on demand
dataGrid.QueryRowHeight += DataGrid_QueryRowHeight;
private void DataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
if (e.RowIndex != 0)
{
//Calculates and sets the height of the row based on its content.
e.Height = dataGrid.GetRowHeight(e.RowIndex);
e.Handled = true;
}
} |
Hi Barak,Thanks for contacting Syncfusion support.You can be achieved AutoRowHeight by handling SfDatagrid.QueryRowHeight event and SfDatagrid.GetRowHeight method. SfDatagrid.QueryRowHeight event returns the row height on demand and SfDatagrid.GetRowHeight method returns the height of the row based on the content. Please refer the below code example
//Hooks QueryRowHeight event in SfDataGrid to set the row height on demanddataGrid.QueryRowHeight += DataGrid_QueryRowHeight;private void DataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e){if (e.RowIndex != 0){//Calculates and sets the height of the row based on its content.e.Height = dataGrid.GetRowHeight(e.RowIndex);e.Handled = true;}}Please refer the below UG link to get more details about AutoRowHeightAutoRowHeight UG link: https://help.syncfusion.com/xamarin/sfdatagrid/row-height-customization#auto-fit-the-grid-rows-based-on-contentRowHeight customization UG link: https://help.syncfusion.com/xamarin/sfdatagrid/row-height-customizationRegards,Ashok
Hi Ashok,
I encounter runtime exception each time I call GetRowHeight() method, and I using GridTemplateColumn in my XAML. Do you have any idea why it crashed when call GetRowHeight()?
SfDataGrid version 15.3.0.33.
Error Message:
Object reference not set to an instance of an object.
StackTrace:
at Syncfusion.SfDataGrid.XForms.Droid.MeasureSize.Convert (Xamarin.Forms.View view, Xamarin.Forms.VisualElement valid) [0x0002c] in <605b15f75385441483a1ceab754f747d>:0
at Syncfusion.SfDataGrid.XForms.Droid.MeasureSize.CalculateHeight (Syncfusion.SfDataGrid.XForms.SfDataGrid grid, Syncfusion.SfDataGrid.XForms.GridColumn column, Xamarin.Forms.View view) [0x0000a] in <605b15f75385441483a1ceab754f747d>:0
at Syncfusion.SfDataGrid.XForms.SfDataGridHelpers.GetTemplateHeight (Syncfusion.SfDataGrid.XForms.SfDataGrid grid, Syncfusion.SfDataGrid.XForms.GridColumn column, System.Object rowData, System.Int32 rowIndex) [0x00060] in <fe30172fa3ba4837bfbe14fa0c90fdf2>:0
at Syncfusion.SfDataGrid.XForms.SfDataGridHelpers.GetRowHeight (Syncfusion.SfDataGrid.XForms.SfDataGrid datagrid, System.Object rowData, System.Int32 rowIndex, Syncfusion.SfDataGrid.XForms.GridRowSizingOptions options) [0x0012e] in <fe30172fa3ba4837bfbe14fa0c90fdf2>:0
at Syncfusion.SfDataGrid.XForms.SfDataGridHelpers.GetRowHeight (Syncfusion.SfDataGrid.XForms.SfDataGrid dataGrid, System.Int32 rowIndex, Syncfusion.SfDataGrid.XForms.GridRowSizingOptions options) [0x000c6] in <fe30172fa3ba4837bfbe14fa0c90fdf2>:0
Regards,
CT
Hi Ashok,
Thanks you for the sample code and I will have a look and compare it with my code.
Cheers,
CT
Hi Chiew,Thanks for contacting Syncfuion support.We have checked your query and prepared the SfDataGrid sample with GridTemplateColumn and set the RowHeight by handling QueryRowHeight event in SfDataGrid v15.3.0.33 and Xamarin.Forms v2.3.3.180 but we are not able to reproduced the issue, SfDataGrid loaded properly and RowHeight has been calculated based on the GridCell value. For your reference we have attached sample and Screenshot in the below location, please check it. Could you please share your SfDataGrid and Xamarin.Forms version details, SfDataGrid.Columns creation code snippet, tested device details? Otherwise please do revert us by modifying our sample to replicate the issue or share your sample along with replication procedure, that would be more helpful for us to proceed further.Regards,Ashok
Hi Ashok,
I manage to locked down the root cause of the problem.
If I compile your sample code with Mono Framework 5.4.1.6, and upgrade the Xamarin.Forms to 2.4.0.38779. The program will crashed when call the DataGrid.GetRowHeight().
(see attachment: Mono Framework 4.8.1.png.zip)
But, when I compile the sample code with Mono Framework 4.8.1 (without changing anything, Xamarin.Forms 2.3.3.180), everything work well.
(see attachment: Mono Framework 5.4.1.6.png.zip)
Therefore, when will this be fix in Xamarin.Forms 2.4.0.38779 with Mono Framework 5.4.1.6 ?
Cheers,
CT
Hi Ashok,
Here is another attached screen captured. Which I missed out in my previous post.
Cheers,
CT