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

Match column title alignments with field alignments in DBGrid

By Zarko Gajic, About.com

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

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

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

Easy ways to connect two computers for networking purposes. 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.