1. Home
  2. Computing & Technology
  3. Delphi Programming

Match column title alignments with field alignments in DBGrid

By , About.com Guide

Alignement of each field's data in a DBGrid can be set using the Alignement property.

Here's how to match Column title alignement with field alignement.

Usage: AlignTitles(DBGrid1) ;

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure AlignTitles(Grid : DBGrid) ;
var
   j, k: Integer;
begin
  with Grid.DataSource.DataSet do
   for j := 0 to -1 + DBGrid1.FieldCount do
    for k := 0 to -1 + FieldCount do
     if Fields[k].FieldName = Grid.Fields[j].FieldName then
      Grid.Columns[j].Title.Alignment := Fields[k].Alignment;
end; (* AlignTitles *)
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to sort items in a TList object
« Delphi: Incompatible type: 'method pointer and regular procedure' - explained

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2003 Delphi Tips
  7. Match column title alignments with field alignments in DBGrid

©2009 About.com, a part of The New York Times Company.

All rights reserved.