This example shows how to handle the CustomDrawCell event to indicate invalid values (display error icons within data cells based on a specific condition).
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) {
BaseEditViewInfo info = ((GridCellInfo)e.Cell).ViewInfo;
string error = GetError(e.CellValue, e.RowHandle, e.Column);
SetError(info, error);
info.CalcViewInfo(e.Cache.Graphics);
}
public string GetError(object value, int rowHandle, GridColumn column) {
if (value == null) return "value is null";
if (!(value is int)) return string.Empty;
if ((int)value % 2 == 0) return "value is even";
if ((int)value < 10) return "value < 10";
return string.Empty;
}
void SetError(BaseEditViewInfo cellInfo, string errorIconText) {
if (errorIconText == string.Empty) return;
cellInfo.ErrorIconText = errorIconText;
cellInfo.ShowErrorIcon = true;
cellInfo.FillBackground = true;
cellInfo.ErrorIcon = DXErrorProvider.GetErrorIconInternal(ErrorType.Critical);
}
- How to show error icons for cells when working in unbound mode
- Access, Modify and Validate Rows and Cells of Data-Aware Control - Cheat Sheets and Best Practices
(you will be redirected to DevExpress.com to submit your response)