Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a custom row cell style event in my winforms project:

private void gridView_Orders_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
            DevExpress.XtraGrid.Views.Grid.GridView View = sender as DevExpress.XtraGrid.Views.Grid.GridView;

            if (e.RowHandle >= 0) // Checks there is a row to customise
                bool HasErrored = (bool)View.GetRowCellValue(e.RowHandle, 
                View.Columns["HasErrored"]); // Finds all the rows that have errored

                if (HasErrored && SupplierOrderNumberDuplicate) // The row has errored and the SupplierOrderNumber is a duplicate

                    e.Appearance.BackColor = Color.Crimson; 
                    e.Appearance.ForeColor = Color.White;                                                                                      

The problem is this colours the whole row and not the individual cell (The cell in the SupplierOrderNumber column. I seem to only be able to find fixes for this for old versions of DevExpress.

What I have tried:

if (e.Column.FieldName == "SupplierOrderNumber")
	bool value = Convert.ToBoolean(View.GetRowCellValue(e.RowHandle, View.Columns["SupplierOrderNumber"]));
	if (value)
		e.Appearance.BackColor = Color.Red;

and this:

if (e.RowHandle == 1 && e.Column.FieldName == "SupplierOrderNumber")
	e.Appearance.BackColor = Color.IndianRed;

I have also tried to do the event in CustomDrawCell as opposed to RowCellStyle but with the same results.
Updated 6-Sep-22 4:58am
[no name] 6-Sep-22 10:30am    
You're coloring the row because you're only referencing the row; you need a reference to the cell.

1 solution

This gets the cell and not the row

if (e.Column.Name == colSupplierOrderNumber.Name)
	if (View.GetRowCellValue(e.RowHandle, colSupplierOrderNumber).ToString() != "")
		int SupplierOrderNumber = Convert.ToInt32(View.GetRowCellValue(e.RowHandle, 

		if (SupplierOrderNumber != 0)
			e.Appearance.BackColor = Color.Crimson; // Changes all the error rows to red
			e.Appearance.ForeColor = Color.White; // Changes text colour to white
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900