我想遍历 DevExpress.GridView.gridcontrol的特定(已知)列的每个单元格,根据特定的单元格值进行一些验证,截至目前我所尝试的如下 - -
for (int i = 0; i < gridView1.Columns.Count; i++)
{
this.gridView1.Columns[i].AppearanceCell.BackColor = Color.Red;
}
使用上面的代码我可以循环遍历DevExpress.GridView.gridcontrol的每一列但无法遍历特定(第i列)列的每个单元格。希望你能理解我想说的话。请帮忙..在此先感谢.. !!
答案 0 :(得分:0)
参考文献中有一些例子:
一个简单的循环:
// iterate cells and compose a tab delimited string of cell values
for (int i = 0; i < m_gridView.RowCount; i++)
{
int rowHandle = m_gridView.GetRowHandle(i);
...
}
// and
for(int i = 0; i < gridView1.DataRowCount; i++)
{
//Do something here
}
看看:
GridView.GetRowCellValue
方法
答案 1 :(得分:0)
最后,我通过使用RowCellStyle事件得到了答案,如下所示 -
private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView View = sender as DevExpress.XtraGrid.Views.Grid.GridView;
if (e.Column.FieldName == "XYZ")
{
string strCellValue = View.GetRowCellDisplayText(e.RowHandle, View.Columns["XYZ"]);
int inStockCol = e.RowHandle;
if (!strCellValue.Equals("NA"))
{
double dblCellValue = Convert.ToDouble(strCellValue);
if (dblCellValue < 0 || dblCellValue > 1000)
{
e.Appearance.BackColor = Color.Red;
e.Appearance.BackColor2 = Color.LightPink;
}
else
{
e.Appearance.BackColor = Color.Green;
e.Appearance.BackColor2 = Color.LightGreen;
}
}
}
}