Articles in this section
Category / Section

How to maintain the background color while selecting the row in WinForms DataGrid?

1 min read

In WinForms DataGrid (SfDataGrid), you can maintain the selection background color for a particular row by setting the SelectionStyle.BackColor in dataGrid.SelectionChanged event. This event triggers when the selection is changed from one row to another.

Kindly refer the below code snippet

sfDataGrid1.SelectionChanged += SfDataGrid1_SelectionChanged;
Color = sfDataGrid1.Style.SelectionStyle.BackColor;


private void SfDataGrid1_SelectionChanged(object sender, Syncfusion.WinForms.DataGrid.Events.SelectionChangedEventArgs e)
{
   if ((e.AddedItems[0] as OrderInfo).Country == "Germany")
   {
       sfDataGrid1.Style.SelectionStyle.BackColor = Color.Red;
       sfDataGrid1.Style.CurrentCellStyle.BackColor = Color.Red;
   }
   else
   {
       sfDataGrid1.Style.SelectionStyle.BackColor = Color;
       sfDataGrid1.Style.CurrentCellStyle.BackColor = Color.White;
   }
}

SfDataGrid_Selection.gif

Take a moment to peruse the WinForms DataGrid - Selection documentation, where you can find about the clipboard operations with code examples.

Conclusion

I hope you enjoyed learning about how to maintain the background color while selecting the row in WinForms DataGrid.

You can refer to our WinForms DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms DataGrid example to understand how to create and manipulate data.

For current customers, you can check out our 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 other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-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