Articles in this section
Category / Section

How to load custom views in .NET MAUI DataGrid (SfDataGrid) cells?

3 mins read

The .NET MAUI DataGrid enables hosting of one or more views within a cell by configuring the DataGridTemplateColumn.CellTemplate property of DataGridTemplateColumn.

Please refer to the code example below, where both an Image and a Label are loaded inside the CellTemplate of DataGridTemplateColumn. It’s important to note that the underlying data object serves as the binding context for both the Image and Label within the CellTemplate.

Xaml:
<syncfusion:SfDataGrid ColumnWidthMode="Auto"
                      SortingMode="Single"
                      ItemsSource="{Binding Employees}">
   <syncfusion:SfDataGrid.Columns>
       <syncfusion:DataGridTemplateColumn MappingName="EmployeeID"
                                          Width="150"
                                          HeaderText="Employee ID">
           <syncfusion:DataGridTemplateColumn.CellTemplate>
               <DataTemplate>
                   <StackLayout Orientation="Horizontal">
                       <Image Source="dotnet_bot.png" />
                       <Label Text="{Binding EmployeeID}"
                              VerticalOptions="Center" />
                   </StackLayout>
               </DataTemplate>
           </syncfusion:DataGridTemplateColumn.CellTemplate>
       </syncfusion:DataGridTemplateColumn>
   </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

Executing the code example above yields the following output.

Download the complete sample from GitHub

Conclusion

I hope you enjoyed learning how to load custom views in .NET MAUI DataGrid (SfDataGrid) cells.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore 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 forums, Direct-Trac or feedback portal, or the 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