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 获取或设置当前可见视图顶部行号、左边位置
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人