[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Collapse]Get Started With Data Grid and Views
     [Collapse]Appearance and Conditional Formatting
       Tutorial: Conditional Formatting
       Tutorial: Custom Drawing
       Tutorial: Custom Styles for Rows and Cells
       Tutorial: View and Column Appearance
     [Expand]Data Editing
     [Expand]Hit Information
     [Expand]Data Binding and Working with Columns
     [Expand]Grid View - Columns, Rows and Cells
     [Expand]Banded Views
     [Expand]WinExplorer View
     [Expand]Tile View
     [Expand]Filter and Search
     [Expand]Split Presentation
     [Expand]Row Preview Sections
   [Expand]Data Binding
    Unbound Columns
   [Expand]Data Editing and Validation
   [Expand]Filter and Search
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
    Hit Information
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Tutorial: Custom Styles for Rows and Cells

This walkthrough is a transcript of the Custom Styles for Rows and Cells video available on the DevExpress YouTube Channel.

In this tutorial, you'll learn how to change data cell styles using events. You'll start with a grid displaying task data and having no conditional formatting applied. By handling the GridView.RowStyle event, you'll apply a different background color to rows whose Priority field value is High. Then, you'll use the GridView.RowCellStyle event to highlight Status cells within those rows, if the Status is set to New.

Expanded Starting Point

Start with an application that has a grid that displays task data and has no conditional formatting applied. Run the application to see how the data looks.

Expanded Customizing the Appearance of Individual Rows

Write the GridView.RowStyle event handler. The code changes the background color for rows whose Priority column value is High. The currently processed row is identified using the event's RowEventArgs.RowHandle parameter. The row's appearance settings are set using the RowStyleEventArgs.Appearance parameter.

Run the application and see the result. The "high priority" rows are now displayed with the specified gradient background. The gradient is applied to the entire row and not to individual cells.

Expanded Customizing the Appearance of Individual Cells

Return to design time and customize individual cells. For this purpose, handle the GridView.RowCellStyle event. It provides you with the CustomRowCellEventArgs.Column and CustomRowCellEventArgs.RowHandle parameters that identify the cell being processed. The handler will modify cells in the Status column if their value is New, provided that the record's Priority is set to High.

Run the application. You'll see that appearance settings imposed by the GridView.RowCellStyle event override those set in the GridView.RowStyle event.

Expanded See Also

Is this topic helpful?​​​​​​​