TcxGrid NewItemRecord Validate(TcxGrid NewItemRecord验证)

2016-09-07 19:21:05来源:CSDN作者:jzt_designer人点击

原文地址:https://www.devexpress.com/Support/Center/Question/Details/Q273430

1、对于绑定的TcxGrid的验证:

You can solve this problem on the DataSet level. Just handle the DataSet's OnBeforePost event, and check necessary values there if the DataSet's state is dsInsert. If certain fields contains incorrect values, you can call the DataSet.Cancel method to cancel changes, or call the Abort method if values are not valid, to prevent the NewItemRow data from disappearing:

[Delphi]Open in popup windowprocedure <aForm>.<aDataSet>BeforePost(DataSet: TDataSet);begin  if (DataSet.State = dsInsert) and <IsRowDataInvalid> then  begin    //Perform your actions    Abort;  end;end;

2、对于非绑定的TcxGrid的验证

You can perform this task at an unbound View's DataController level. Just handle the DataController's OnBeforePost event and check the record's data there. If data is invalid, call the Abort method:

[Delphi]Open in popup windowprocedure <aForm>.<aView>DataControllerBeforePost(  ADataController: TcxCustomDataController);var  AController: TcxCustomGridTableController;begin  AController := TcxGridDataController(ADataController).GridView.Controller;  if AController.NewItemRecordFocused then    if not  <IsRecordDataValid(AController.FocusedRecord)> then    begin      //Perform your actions      Abort;    end;end;

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台