Articles in this section
Category / Section

How to adjust row heights of each row based on their content in MAUI DataGrid (SfDataGrid)?

2 mins read

The .NET MAUI DataGrid (SfDataGrid) allows you to customize the RowHeight of grid rows using the QueryRowHeight event. You can auto fit a row based on its content by using the GetIntrinsicRowHeight method.

Note:

Handled property of the QueryRowHeightEventArgs must be set to true in the QueryRowHeight event for the height changes to take effect.

XAML

<syncfusion:SfDataGrid x:Name="dataGrid"
                    ItemsSource="{Binding OrdersInfo}"
                AutoGenerateColumnsMode="None">
    <syncfusion:SfDataGrid.Columns>
        <syncfusion:DataGridTextColumn MappingName="OrderId" HeaderText="Order ID" />
        <syncfusion:DataGridTextColumn MappingName="CustomerId"  HeaderText="Customer ID"/>
        <syncfusion:DataGridTemplateColumn MappingName="CustomerQuery" HeaderText="Customer Query">
            <syncfusion:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Label Text="{Binding CustomerQuery}"/>
                </DataTemplate>
            </syncfusion:DataGridTemplateColumn.CellTemplate>
        </syncfusion:DataGridTemplateColumn>
        <syncfusion:DataGridTextColumn MappingName="Country" />
    </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

C#

public partial class MainPage : ContentPage
{
 public MainPage()
 {
  InitializeComponent();
        dataGrid.QueryRowHeight += DataGrid_QueryRowHeight;
 }
 
    private void DataGrid_QueryRowHeight(object sender, Syncfusion.Maui.DataGrid.DataGridQueryRowHeightEventArgs e)
    {
        if (e.RowIndex > 0)
        {
            e.Height = e.GetIntrinsicRowHeight(e.RowIndex);
            e.Handled= true;
        }
    }
}

 

Note:

To skip the header row the condition (e.RowIndex > 0) is added.

how to adjust row heights of each row based on their content.

View Sample on GitHub

Take a moment to pursue this documentation, where you can find more about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples.

Please refer to this link to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid).

Conclusion

I hope you enjoyed learning about how to adjust row heights of each row based on their content in MAUI DataGrid (SfDataGrid).

You can refer to our .NET MAUI DataGrid’s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.

For current customers, you can check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied