Home DBAdvGrid RowHeights - alter all rows except 1
Reply: 1

DBAdvGrid RowHeights - alter all rows except 1

Petzy
1#
Petzy Published in 2017-09-11 04:10:35Z

I'm using the following code in the CustomCellDraw event of DBAdvGrid(TMS) to increase row height.

procedure TForm1.DBAdvGrid1CustomCellDraw(Sender: TObject; Canvas: TCanvas;
  ACol, ARow: Integer; AState: TGridDrawState; ARect: TRect; Printing: Boolean);
begin
DBAdvGrid1.RowHeights[ARow]:=120;
end;

How do I make it avoid increasing row 0, which is the 1st row in the Grid, containing column names/headers? - I'd like that row to remain untouched while all the rest should get resized via the above code. Basically it should ignore row index 0 and start from row index 1

Victoria
2#
Victoria Reply to 2017-09-11 06:01:43Z

It would be like this:

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;

But do not modify row heights from a drawing event. Such event is triggered frequently, and is used exclusively for content painting, not for adjusting content size. What's worse, if you e.g. allowed row sizing and the user would try to setup row height, it would in turn trigger that event where you would change the height back, so you'd be fighting with the user.

Content sizing should be done earlier, as this example shows in the OnCustomCellSize event.

But for your aim I think it's enough to set DefaultRowHeight and FixedRowHeight properties with no additional code.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311198 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO