Category / Section
How to change the cell background based on the cell value in WinForms DataGrid(SfDataGrid)?
1 min read
You can apply the background color for cell based on cell value can be achieve by using SfDataGrid.QueryCellStyle event.
sfDataGrid1.QueryCellStyle += SfDataGrid1_QueryCellStyle; private void SfDataGrid1_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e) { if (e.Column.MappingName == "Color") { var userColourString = e.DisplayText; int userColourNumeric = 0; int.TryParse(userColourString, out userColourNumeric); var colourToUse = userColourNumeric; e.Style.BackColor = ColorTranslator.FromWin32(colourToUse); if (e.DisplayText == "0") e.Style.TextColor = Color.White; } }