cxGrid 知识点

  • cxGrid 知识点

    • 设置 TableView.OptionsView.HeaderAutoHeight 为 True 时栏目标题高度自动调整
    • 网格上选择了记录,当焦点移走时,看不到选择的记录,解决办法:修改 TableView 的属性,OptionsSelection->HideSelection 设为 False
    • 遍历选中记录:
      with ATableView.DataController do
      begin
      VOldFocusedRecordIndex := FocusedRecordIndex;

      for VIndex := 0 to ATableView.Controller.SelectedRowCount - 1 do
      begin
      FocusedRecordIndex := ATableView.Controller.SelectedRows[VIndex].RecordIndex;
      AQry.UpdateObject.ExecSQL(ukInsert);
      end;

      FocusedRecordIndex := VOldFocusedRecordIndex;
      end;

    • 遍历当前视图所有记录:
      with ATableView.DataController do
      begin
      VOldFocusedRecordIndex := FocusedRecordIndex;

      for VIndex := 0 to FilteredRecordCount - 1 do
      begin
      FocusedRecordIndex := FilteredRecordIndex[VIndex];
      AQry.UpdateObject.ExecSQL(ukInsert);
      end;

      FocusedRecordIndex := VOldFocusedRecordIndex;
      end;

    • 调用 TableView 的 DataController.Groups.FullExpand 方法展开所有节点
    • 在使用自定义数据源,删除记录时,先 BeginUpdate,处理完后再 EndUpdate,否则会偶尔抛出索引超出范围:
      tvProducePlan.BeginUpdate;
      try
      FCustomDataSource.DeleteSelectedRecord(GetSelectedIds);
      finally
      tvProducePlan.EndUpdate;
      end;
    • 获取选中记录某列的值:
      function TMainForm.GetSelectedIds: TStringArray;
      var
      VIndex: Integer;
      begin
      SetLength(Result, tvProducePlan.Controller.SelectedRowCount);
      for VIndex := 0 to tvProducePlan.Controller.SelectedRowCount - 1 do
      Result[VIndex]:= tvProducePlan.DataController.Values[tvProducePlan.Controller.SelectedRecords[VIndex].RecordIndex, 0];
      end;
    • 根据某网格的数据定位另一个网格:
      procedure TMainForm.LinkFocusRecord(AParentColumn, AChildColumn: TcxGridColumn; AParentGrid, AChildGrid: TcxGridTableView);
      var
      VIndex: Integer;
      VValue: STring;
      FocusedRecord: TcxGridFocusedRecordChangedEvent;
      begin
      FocusedRecord:= AParentGrid.OnFocusedRecordChanged;
      AParentGrid.OnFocusedRecordChanged := nil;
      try
      with AChildGrid.DataController do
      begin
      VValue := GetDisplayText(FocusedRecordIndex, AChildColumn.Index);
      end;

      VIndex := AParentGrid.DataController.FindRecordIndexByText(0, AParentColumn.Index, VValue, False, False, True);

      if VIndex < 0 then
      begin
      AParentGrid.DataController.ClearSelection;
      Exit;
      end;

      AParentGrid.DataController.FocusedRecordIndex := VIndex;
      AParentGrid.DataController.SyncSelectionFocusedRecord;
      finally
      AParentGrid.OnFocusedRecordChanged := FocusedRecord;
      end;
      end;

    • TableView 的 FocusedRecordChanged 事件表示当前聚焦记录改变
    • 使用 TcxGridTableView.Controller 的 TopRowIndex、LeftPos 获取或设置当前可见视图顶部行号、左边位置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蝈蝈(GuoGuo)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值