Text vertically aligned in a TwwDBGrid cell
If I increment the RowHeightPercent property of a TwwDBGrid, for example from 100 to 125, without changing the TwwDBGrid font size, I get more spaced rows (that's what I need) but the text isn't vertically aligned in the cells (still on top of the cells). Is there a property able to manage the vertical alignment of text in dbgrid cells? Sorry but I didn't find it ... Is there another way to get the vertical alignment of text working in dbgrid cells?
Thanks
Massimo
-
Hi Massimo, for some reason we were having notification problems with the zen desk system. Hopefully that is cleared up now. Now to answer your questions.
I believe they should be aligned to top. If you are trying to center the data, you could use the grid events to change the painting. For instance using both the OnAfterDrawCell and OnBeforeDrawCell you can change the text to vertically aligned. This code does it for the field 'first name'
procedure TGridMemoApp.wwDBGrid1AfterDrawCell(Sender: TwwCustomDBGrid;
DrawCellInfo: TwwCustomDrawGridCellInfo);
var s: string;
h, t: integer;
begin
if (drawcellinfo.Field<>nil) and (drawcellinfo.DataRow>=0) and
(drawcellinfo.Field.FieldName = 'First Name') then
begin
s:= DrawCellInfo.Field.AsString;
h:= Sender.Canvas.TextHeight(s);
t:= DrawCellInfo.Rect.Top + (DrawCellInfo.Rect.Height - h) div 2;
Sender.Canvas.TextRect(DrawCellInfo.Rect, DrawCellInfo.Rect.left, t, s);
end;
end;
procedure TGridMemoApp.wwDBGrid1BeforeDrawCell(Sender: TwwCustomDBGrid;
DrawCellInfo: TwwCustomDrawGridCellInfo);
begin
if (drawcellinfo.Field<>nil) and (drawcellinfo.DataRow>=0) and
(drawcellinfo.Field.FieldName = 'First Name') then
begin
DrawCellInfo.DefaultDrawContents:= false;
end;
end;
Please sign in to leave a comment.
Comments
1 comment