I have a devexpress xtragrid with 40 columns. I compare each cell value with other and if it is different then I want to change the cell background color. I try with GridViewInfo but it only takes the columns that are visible on the screen.But I want to do for all the columns.(Not with RowCellStyle) Do you have a solution for that? Thank you!
Asked
Active
Viewed 3.4k times
3 Answers
7
You need to handle the CustomDrawCell of your GridView, here is a snip of code that change the color of the Name column, based on an other column valoe (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

SidAhmed
- 2,332
- 2
- 25
- 46
5
Hook onto the RowStyle event of your xtragrid.
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;
}
}
}
-
The compare function is on a button .How can I call RowStyle event? – Lavy Jun 29 '12 at 13:57
-
You can not do this on button click event. you must handle either `RowStyle` or `CustomDrawCell`. put their condition there and simply invalidate the grid after making changes to that data on button.. – Niranjan Singh Jul 02 '12 at 11:42