我在CustomCellDraw
(TMS)的DBAdvGrid
事件中使用以下代码来增加行高。
procedure TForm1.DBAdvGrid1CustomCellDraw(Sender: TObject; Canvas: TCanvas;
ACol, ARow: Integer; AState: TGridDrawState; ARect: TRect; Printing: Boolean);
begin
DBAdvGrid1.RowHeights[ARow]:=120;
end;
如何避免增加第0行,这是Grid中的第1行,包含列名/标题? - 我希望这一行保持不变,而所有其余部分都应通过上面的代码调整大小。基本上它应该忽略行索引0并从行索引1开始
答案 0 :(得分:1)
就像这样:
procedure TForm1.DBAdvGrid1CustomCellDraw(Sender: TObject; Canvas: TCanvas;
ACol, ARow: Integer; AState: TGridDrawState; ARect: TRect; Printing: Boolean);
begin
if ARow > 0 then
DBAdvGrid1.RowHeights[ARow] := 120;
end;
但是不要修改绘图事件的行高。此类事件经常被触发,专门用于内容绘制,而不是用于调整内容大小。更糟糕的是,如果你是允许行大小调整,用户会尝试设置行高,它会反过来触发那个你要改变高度的事件,这样你就可以与用户战斗了。
内容大小调整应该提前完成,因为this example会在 OnCustomCellSize 事件中显示。
但为了您的目标,我认为只需设置 DefaultRowHeight 和 FixedRowHeight 属性即可,无需其他代码。