cxGrid 回车自动添加新行
<AView>.NewItemRow.Visible = True
<AView>.OptionsBehavior.GoToNextCellOnEnter = True
procedure <AForm>.<AView>EditKeyDown(Sender: TcxCustomGridTableView;
AItem: TcxCustomGridTableItem; AEdit: TcxCustomEdit; var Key: Word;
Shift: TShiftState);
begin
if (Key = 13) and (Sender.DataController.FocusedRecordIndex = -1) and (AItem.VisibleIndex = Sender.VisibleItemCount - 1) then
// <ADataSet>.Post; // 绑定数据集的 View
Sender.DataController.Append; // 未绑定数据集的 View
end;
以上是使用 NewItemRow 添加新行的方法,下面的方法可以在最后一行时按回车键添加新行,需要配合设置
procedure TForm1.cv1EditKeyDown(Sender: TcxCustomGridTableView;
AItem: TcxCustomGridTableItem; AEdit: TcxCustomEdit; var Key: Word;
Shift: TShiftState);
begin
if (Key = 13) and (Sender.DataController.FocusedRecordIndex = Sender.DataController.RecordCount -1) then
Sender.DataController.Append;
end;

浙公网安备 33010602011771号