TcxGrid NewItemRecord Validate(TcxGrid NewItemRecord验证)

来源:互联网 发布:杭州创业软件实施 编辑:程序博客网 时间:2024/06/14 14:53

原文地址: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 window
procedure <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 window
procedure <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;

0 0
原创粉丝点击