Current filter:
                                You should refresh the page.
                                Support Center
                                  • How do I set the color or a row based on a value in a column?

                                1 Solution

                                Creation Date Rating Importance Sort by

                                There are two solutions:
                                1. Define a style condition;
                                2. Handle the RowCellStyle event.
                                This article explains the second solution.

                                You should set the e.Appearance.BackColor parameter within the RowCellStyle event handler. A cell is defined by the e.RowHandle and e.Column parameters; the cell's value is passed to the e.CellValue parameter.

                                Our task is to change the style of the whole row. This means that the e.Column parameter should be ignored. A certain column's value can be obtained via the GetRowCellValue method.

                                private bool IsShipToUSCanada(GridView view, int row) { try { string val = Convert.ToString(view.GetRowCellValue(row, "ShipCountry")); return (val == "US" || val == "Canada"); } catch { return false; } } private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { if(IsShipToUSCanada(gridView1, e.RowHandle)) { e.Appearance.BackColor = Color.LightGray; } }
                                Private Function IsShipToUSCanada(ByVal view As GridView, ByVal row As Integer) As Boolean Try Dim val As String = Convert.ToString(view.GetRowCellValue(row, "ShipCountry")) Return (val = "US" OrElse val = "Canada") Catch Return False End Try End Function Private Sub gridView1_RowCellStyle(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs) Handles gridView1.RowCellStyle If IsShipToUSCanada(gridView1, e.RowHandle) Then e.Appearance.BackColor = Color.LightGray End If End Sub

                                If you need to change the style of a single cell (column) instead of a row, you will need to check the e.Column parameter: change e.Appearnace only if e.Column denotes the desired column.

                                See Also:
                                Customizing Appearances of Individual Rows and Cells
                                How to customize the Look-And-Feel of my grid cells

                                If you need additional product information, write to us at or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners