1
votes

I would like to know how to show the column title in dbgrid delphi vertical. At this stage the title headings is a bit long and i want to display them vertical. I am using delphi 2010 and there is nothing in the object inspector to set any allignment settings for vertical or 90 degrees. Any help will be appreciated.

1
At least in Delphi 2009, there's the Font.Orientation property which, if you set to 900 (which equals to 90°) will render the font vertically. The problem is how to increase the height of the header or how to re-position the rendered caption, the best would be still to have a owner draw event for this. - TLama
The font.Orientation changes the font to vertical in the dbgrid itself and not the column headings. - Pierre Kruger
@Pierre: You can set the font for the column header directly. Edit the Column, expand the Title, expand the Font. You can also set it for the entire DBGrid using the TitleFont properties. - Ken White

1 Answers

1
votes

You can do this by doing a couple of things:

  • Set the TDBGrid.TitleFont.Orientation to 900, which is 90 degrees.

  • Use an interposer class to change the TDBGrid first (column header) row height. The interposer class gives you access to the RowHeights property of the grid, which isn't published in TDBGrid:

    implementation

    type
      THackGrid=class(TDBGrid);

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      THackGrid(DBGrid1).RowHeights[0] := 300;        
    end;

Calculating the proper height to use for RowHeights[0] is an exercise left to you. :-) As @TLama said in his comment, you're better off owner-drawing the grid to get the proper fit and alignment of the text; how to do so would be another question (but there are examples that exist already for doing so, so make sure you look at them first before asking it).