How to change current cell background in .NET MAUI DataGrid (SfDataGrid) ?
In this article, we will demonstrate how to change the background of the cell currently being edited in .NET MAUI DataGrid.
C#
The following code shows how to change the background of the cell being edited in the DataGrid:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
dataGrid.CellRenderers.Remove("Text");
dataGrid.CellRenderers.Add("Text", new CustomTextRenderer());
}
}
public class CustomTextRenderer : DataGridTextBoxCellRenderer
{
public override void OnInitializeEditView(DataColumnBase dataColumn, SfDataGridEntry view)
{
base.OnInitializeEditView(dataColumn, view);
if (view != null && view is Entry entry)
{
entry.Background = Colors.SkyBlue;
}
}
}
Please note that we have achieved this only for the DataGridTextColumn. If you need to achieve it for other columns, you will need to write the respective custom renderers.
Output
Download the complete sample from GitHub
Conclusion
I hope you enjoyed learning how to change the current cell background in .NET MAUI DataGrid.
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!