How to change cell background color in Devexpress Grid?

I have a devexpress xtragrid with 40 columns. I compare each cell value with a different one, and if it is different, I want to change the background color of the cell. I am trying to use GridViewInfo, but it only accepts columns that are visible on the screen. But I want to do for all columns. (Not with RowCellStyle) Do you have a solution for this? Thanks!

+6
source share
3 answers

Connect to your xtragrid's RowStyle event.

private void maintainDataControl_RowStyle(object sender, RowStyleEventArgs e) { if (e.RowHandle >= 0) { GridView view = sender as GridView; // Some condition if((string)view.GetRowCellValue( e.RowHandle, view.Columns["SomeRow"]).Equals("Some Value")) { e.Appearance.BackColor = Color.Green; } } } 
+4
source

You need to process the CustomDrawCell of your GridView, here is a code snippet that changes the color of the Name column based on another valoe column (age column)

 private void gridView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e) { if (e.Column == colName) { var age = Convert.ToInt32(gridView.GetRowCellValue(e.RowHandle, colAge)); if (age < 18) e.Appearance.BackColor = Color.FromArgb(0xFE, 0xDF, 0x98); else e.Appearance.BackColor = Color.FromArgb(0xD2, 0xFD, 0x91); } } 

Good luck.

+5
source
+2
source

Source: https://habr.com/ru/post/919330/


All Articles