procedure TMainForm.UniFormCreate(Sender: TObject); begin with UniMDBGrid1 do begin // 1. 开启网格固定列支持(必须,否则Fixed属性无效) Options := Options + [goFixedVertLine, goFixedHorzLine]; // 显示固定列边框 Options := Options - [goColSizing]; // 可选:禁止拖动固定列改变宽度(防止错位) // 2. 锁定第一列(Index=0,UniMDBGrid列索引从0开始) if Columns.Count > 0 then // 先判断有列,避免数组越界 begin Columns[0].Fixed := True; // 核心属性:设为True表示固定该列 Columns[0].FixedWidth := 100; // 固定列宽度(单位:像素,根据需求修改) Columns[0].Title.Alignment := taCenter; // 可选:列标题居中 Columns[0].Alignment := taCenter; // 可选:列内容居中 end; // 3. 可选:设置固定列样式(区分普通列,视觉更清晰) Columns[0].Color := clInfoBk; // 固定列背景色(浅灰色,可自定义) Columns[0].Title.Color := clBtnFace; // 固定列标题背景色 end; end;
浙公网安备 33010602011771号