I want to traverse through each cell of particular (Known) column of DevExpress.GridView.gridcontrol to put some validation depending on particular cell value, as of now what I have tried is as follows--
for (int i = 0; i < gridView1.Columns.Count; i++)
{
this.gridView1.Columns[i].AppearanceCell.BackColor = Color.Red;
}
Using above code I can can loop through each column of DevExpress.GridView.gridcontrol but unable to loop through each cell of particular (i-th) column . Hope you understand what I'm trying to say. Please help.. Thanks in advance..!!
There are examples of that in the reference:
And a simple loop:
// 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
}
look also at: GridView.GetRowCellValue
method
Finally I got the answer it is done by using RowCellStyle event as follows--
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;
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.