表格輸入錯誤提示

using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Columns;

private void gridView1_ValidateRow(object sender, 
DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) {
    ColumnView view = sender as ColumnView;
    GridColumn column1 = view.Columns["StartTime"];
    GridColumn column2 = view.Columns["EndTime"];
    //Get the value of the first column
    DateTime time1 = (DateTime)view.GetRowCellValue(e.RowHandle, column1);
    //Get the value of the second column
    DateTime time2 = (DateTime)view.GetRowCellValue(e.RowHandle, column2);            
    //Validity criterion
    if (time1 >= time2) {
        e.Valid = false;
        //Set errors with specific descriptions for the columns
        view.SetColumnError(column1, "The value must be less than EndTime");
        view.SetColumnError(column2, "The value must be greater than StartTime");
    }
}

private void gridView1_InvalidRowException(object sender, 
DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs e) {
    //Suppress displaying the error message box
    e.ExceptionMode = ExceptionMode.NoAction;
}
發佈了22 篇原創文章 · 獲贊 11 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章