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 添加新行的方法,下面的方法可以在最后一行时按回车键添加新行,需要配合设置 .OptionsBehavior 下面几个按键相关的属性。

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;
posted @ 2024-11-17 10:13  汉学  阅读(20)  评论(0)    收藏  举报