参考链接:http://www.cnblogs.com/rwh871212/p/6756091.html?utm_source=itdadao&utm_medium=referral
使用事件customRowCell... 不要老想着遍历。
贴上代码,帮忙看看是否有问题
private void grvDetail_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
int hand = e.RowHandle;
if (hand < 0)
return;
DataRow dr = this.gridView1.GetDataRow(hand);
if (dr == null)
return;
for (int i = 0; i < gridView1.RowCount; i++)
{
string sscode = gridView1.GetRowCellValue(i, gridView1.Columns[0]).ToString();
for (int j = 5; j <= 11; j++)
{
if (gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns[j]).ToString() != "")
{
string eqpcode = "";
string opdesc = "";
string mocode = "";
string itemcode = "";
//string cName = "colOP" + "j";
string set = gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns[j]).ToString();
string[] sArray = set.Split(' ');
if (sArray.Length == 4)
{
eqpcode = sArray[0];
opdesc = sArray[1];
mocode = sArray[2];
itemcode = sArray[3];
}
DataTable dt =。。。。。
if (dt != null && dt.Rows.Count > 0)
{
if (e.Column.FieldName == gridView1.Columns[j].FieldName)//设背景
{
if (dt.Rows[0]["EndDate"].ToString() == "" && dt.Rows[0]["EndTime"].ToString() == "")
{
e.Appearance.BackColor = Color.Blue;
}
else
{
e.Appearance.BackColor = Color.LimeGreen;
}
}
}
}
}
}
@小太阳与码农:
private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e) { GridView view = sender as GridView; if(view == null) return; if(e.RowHandle != view.FocusedRowHandle && ((e.RowHandle % 2 == 0 && e.Column.VisibleIndex % 2 == 1) || (e.Column.VisibleIndex % 2 == 0 && e.RowHandle % 2 == 1))) e.Appearance.BackColor = Color.NavajoWhite; }
DEV官方代码。
@爱编程的大叔: 主要是不寄到怎么加上单元格值的判断呐