- Home
- Forum
- Xamarin.Forms
- Resetting the row height after the cell content changes.
Resetting the row height after the cell content changes.
Hi,
Alfredo
I am having some trouble changing the height of a row after changing its content. I have intercepted the DataGrid_QueryRowHeight event as indicated by https://help.syncfusion.com/xamarin/datagrid/row-height-customization:
private void _tableDataGrid_QueryRowHeight(object sender, Syncfusion.SfDataGrid.XForms.QueryRowHeightEventArgs e)
{
if (e.Height != _tableDataGrid.RowHeight)
return;
if (e.RowIndex != 0)
{
e.Height = _tableDataGrid.GetRowHeight(e.RowIndex);
e.Handled = true;
}
}
This successfully sets the initial height of all the rows. At some point in the program I have the following code to set the text in the view model, which changes the text in a cell on the 4th row:
itemsVM.DynamicCollection[4].Values[2].StringDisplayValue = str;
_tableDataGrid.InvalidateRowHeight(4, false); // I have tried both 'true' and 'false' for the second argument.
The first line successfully changes the text on the cell for the 4th row. The second line calls InvalidateRowHeight to recalculate the height of the row. However, the call to InvalidateRowHeight is not firing the QueryRowHeight event, so the height of the row is not recalculated.
Can you tell me if I'm doing something wrong?
Thanks,
Alfredo
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
PK
Pradeep Kumar Balakrishnan
Syncfusion Team
June 11, 2020 05:31 PM UTC
Hi Alfredo,
Thank you for contacting Syncfusion support.
We have checked your query “DataGrid QueryRowHeight event is not raised when refreshing an row using InvalidateRowHeight method in Xamarin forms” and we noticed that Query Row Height event is raised and return in if (e.Height != _tableDataGrid.RowHeight) so row height is not calculated for the refreshed ro. Please refer the modified code snippet to achieve this requirement.
Code Snippet:
|
bool propertyChanged;
public MainPage()
{
InitializeComponent();
}
private void dataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
if(propertyChanged)
{
e.Height = dataGrid.GetRowHeight(e.RowIndex);
e.Handled = true;
}
if (e.Height != dataGrid.RowHeight)
return;
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;
}
}
private void Button_Clicked(object sender, EventArgs e)
{
propertyChanged = true;
viewModel.OrdersInfo[3].FirstName = "Modified through Button click";
dataGrid.InvalidateRowHeight(4, true);
} |
We hope this helps. Please let us know, if you need any further assistance.
Regards,
Pradeep Kumar B
Marked as answer
PR
Padmini Ramamurthy
Syncfusion Team
June 16, 2020 04:58 AM UTC
From: Alfredo Diaz
Sent: Monday, June 15, 2020 12:53 PM
To: Syncfusion Support <[email protected]>
Subject: RE: Syncfusion support community forum 155080, Resetting the row height after the cell content changes., has been updated.
Sent: Monday, June 15, 2020 12:53 PM
To: Syncfusion Support <[email protected]>
Subject: RE: Syncfusion support community forum 155080, Resetting the row height after the cell content changes., has been updated.
Hi Pradeep,
I finally got around to testing this and it worked as expected. Thank you for your swift reply!
Alfredo Diaz
KK
Karthikraja Kalaimani
Syncfusion Team
June 16, 2020 09:03 AM UTC
Hi Alfredo,
Thank you for the update. We glad to know that your requirement has been achieved. Please let us know if you have any further queries on this. We are happy to help you.
Regards,
Karthik Raja
Thank you for the update. We glad to know that your requirement has been achieved. Please let us know if you have any further queries on this. We are happy to help you.
Regards,
Karthik Raja
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
- Marked answer
-
AL Alfredo
- Jun 10, 2020 06:58 PM UTC
- Jun 16, 2020 09:03 AM UTC