GridControl cell editing verification method

This article demonstrates the method of Example DevExpress implemented GridControl cell editing verified, more practical feature, as follows:

The main function code is as follows:

///  <Summary> 
/// custom cell validation
 ///  </ Summary> 
///  <param name = "View"> the GridView </ param> 
///  <param name = "E"> BaseContainerValidateEditorEventArgs < / param> 
///  <param name = "fieldNameHandler"> Principal </ param> 
///  <param name = "errorHanlder"> Principal </ param> 
///  <param name = "the errorText"> when the authentication fails of the time, the error message text </ param> 
public  static  void CustomValidatingEditor ( the this the GridView View,BaseContainerValidateEditorEventArgs e, Predicate<string> FieldNameHandler, the Predicate < Object > errorHanlder, String the errorText) 
{ 
  / * Description 
   * in the event ValidatingEditor 
   * EG: 
   * String [] = workType new new String [. 4] { "-1", "closed but not delete", "Enable "," delete "}; 
   * void gvLampConfig_ValidatingEditor (Object SENDER, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs E) 
   * { 
   * SENDER AS = the GridView the _view the GridView; 
   * _view.CustomValidatingEditor (E, the fieldName => fieldName.Equals (" TLampWorkStatus " ), value => workType.Contains <string > (value.ToString ()), " if you want to not modify, can enter -1");! 
   *} 
   * / 
  IF (fieldNameHandler (view.FocusedColumn.FieldName))
  {
 if (errorHanlder(e.Value))
 {
   e.Valid = false;
   e.ErrorText = errorText;
 }
  }
}

 

Code is used as follows:

string[] workType = new string[4] { "-1", "关闭但不删除", "启用", "删除" };
void gvLampConfig_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
{
  GridView _view = sender as GridView;
  _view.CustomValidatingEditor(e, fieldName => fieldName.Equals("TLampWorkStatus"), value => !workType.Contains<string> (value.toString ()), " if you want to not modify, can enter -1 " ); 
}

 

Guess you like

Origin www.cnblogs.com/MuNet/p/11487924.html