/winforms-grid-show-error-icons

Display error icons within grid cells based on a specific condition.

Primary LanguageC#OtherNOASSERTION

WinForms Data Grid - Display error icons within unbound column cells

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

Files to Review

Documentation

See Also

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)