2012-06-29 433 views
6

我有一个40列的devexpress xtragrid。 我比较每个细胞值与其他,如果它不同,那么我想改变细胞的背景颜色。 我尝试使用GridViewInfo,但它只需要在屏幕上可见的列。但是我想为所有列执行操作(不适用于RowCellStyle) 您是否有解决方案? 谢谢!如何在Devexpress Grid中更改单元格的背景颜色?

回答

4

挂钩到xtragrid的RowStyle事件。

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; 
     } 
    } 
} 
+0

比较功能上的按钮,我。怎么可以叫RowStyle事件? – Lavy

+0

你不能在按钮点击事件上做到这一点。你必须处理'RowStyle'或'CustomDrawCell'。把他们的条件放在那里,并在对按钮上的数据进行更改后简单地使网格失效。 –

+0

我已经使用RowCellStyle.Thanks获得了帮助!:) – Lavy

5

您需要处理CustomDrawCell你的GridView的,这里是一个代码剪断的是改变名称栏的颜色,基于另一列valoe(年龄列)

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); 
     } 
    } 

好运

相关问题