Articles in this section
Category / Section

How to show multi-line header text in .NET MAUI DataGrid?

3 mins read

The .NET MAUI DataGrid (SfDataGrid) allows you to customize the header text for a column using the HeaderText property. However, by default, the grid only displays one line of text in the header, and any longer header text will be clipped and show an ellipsis at the end.

To display longer header text, use the HeaderTemplate property in the DataGridColumn. This property replaces the default header view, and you can use it to display a label with the LineBreakMode property set to WordWrap. This will wrap the header text to the next line. Additionally, use the HeaderRowHeight property to adjust the header row height as needed, depending on the length of your header text.

Refer to the code example below, which illustrates how to show a multiline header in SfDataGrid.

XAML

<ContentPage.BindingContext>
        <local:EmployeeViewModel x:Name="viewModel"/>
    </ContentPage.BindingContext>
<syncfusion:SfDataGrid x:Name="dataGrid"
                        ItemsSource="{Binding Employees}" HeaderRowHeight="70">
    <syncfusion:SfDataGrid.Columns>
        <syncfusion:DataGridTextColumn MappingName="EmployeeID">
            <syncfusion:DataGridTextColumn.HeaderTemplate>
                <DataTemplate>
                    <Label Text="Demo For Multi line Text in header"
                TextColor="Black" VerticalOptions="Fill"
                LineBreakMode="WordWrap” />
                </DataTemplate>
            </syncfusion:DataGridTextColumn.HeaderTemplate>
        </syncfusion:DataGridTextColumn>
    </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

 Output

how to set multi line header text in datagrid column


Download the complete sample from GitHub.

Conclusion

I hope you enjoyed learning how to display multi-line header text in the MAUI DataGrid.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our Documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. 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