I have cell name "MY_CELL" I want to create if "MY_CELL" value is OK! then that Row color will be changed with GreenYellow.
private void gridView2_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
if (gridView2.RowCount > 0)
{
for (int i = 0; i < gridView2.DataRowCount; i++)
{
string text_sms2 = gridView2.GetRowCellValue(i, "MY_CELL").ToString();
if (text_sms2.Contains("ok"))
{
e.Appearance.BackColor = Color.GreenYellow;
}
else
{
e.Appearance.BackColor = Color.Red;
}
}
}
}
These code seems like works but all my rows color changed with "GreenYellow".
There's no need for the loop, since RowStyle event is raised for each individial row. Your code is setting apperence for each row according to the value in the last one.
Try this:
private void gridView2_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) {
if (e.RowHandle >= 0) {
e.HighPriority = true;
var text = gridView2.GetRowCellDisplayText(e.RowHandle, view.Columns["MY_CELL"]);
if(text.Contains("ok") { // mind case sensitivity!!!
e.Appearance.BackColor = Color.GreenYellow;
}
else {
e.Appearance.BackColor = Color.Red;
}
}
}