How to color selected rows in GridView in c#

Vaseph picture Vaseph · Oct 2, 2013 · Viewed 10.1k times · Source

I select all row with follow code in gridview

gridView1.SelectAll();

Now i want to color selected rows in gridview for example blue color.

how can i do it?

Answer

DmitryG picture DmitryG · Oct 2, 2013

I believe you are talking about the DevExpress XtraGrid. If so, then there are multiple approaches to highlight the specific row in DevExpress XtraGrid depending on your task specific. For example, to highlight any selected row you can use the following code:

gridView1.Appearance.SelectedRow.BackColor = Color.Red;

To highlight the specific rows by using custom conditions you can use the GridView.RowStyle event:

void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) {
    if((e.State & DevExpress.XtraGrid.Views.Base.GridRowCellState.Selected) != 0) {
        // check some conditions
        e.HighPriority = true;
        e.Appearance.BackColor = Color.Blue;
    }
}

Please read more about all these approaches in the following help-article: Customizing Appearances of Individual Rows and Cells