Recent

Author Topic: TsWorksheetGrid headers and cell formatting  (Read 293 times)

dodgebros

  • Full Member
  • ***
  • Posts: 161
TsWorksheetGrid headers and cell formatting
« on: November 21, 2023, 05:17:46 am »
How do I add the column names, i.e. column headers, to the TsWorksheetGrid?  At the moment I am doing this on the FormActivate event:
Code: Pascal  [Select][+][-]
  1.  // load column names
  2.       WkBkGrid.Cells[1,1] := 'Grower ID';
  3.       WkBkGrid.Cells[2,1] := 'Plant ID';
  4.       WkBkGrid.Cells[3,1] := 'Plant Name';
  5.       WkBkGrid.Cells[4,1] := 'Size';
  6.       WkBkGrid.Cells[5,1] := 'Description';
  7.       WkBkGrid.Cells[6,1] := 'Price';
  8.       WkBkGrid.Cells[7,1] := 'Size Code';
  9.       WkBkGrid.Cells[8,1] := 'Category Code';
  10.       WkBkGrid.Cells[9,1] := '   Updated   ';
  11.       WkBkGrid.Cells[10,1] := 'Online Only (x)';  
  12.  

Is there a better way?

Also, I need to center the column names in their cells horizontally, how can I do this?
Thanks,
TD

wp

  • Hero Member
  • *****
  • Posts: 11455
Re: TsWorksheetGrid headers and cell formatting
« Reply #1 on: November 21, 2023, 11:28:09 am »
Use the grid property HorAlignment[ACol, ARow: Integer] or HorAlignments[ALeft, ATop, ARight, ABottom: Integer]:
Code: Pascal  [Select][+][-]
  1.   WkBkGrid.HorAlignment[1, 1] := haCenter;
  2.   WkBkGrid.HorAlignment[2, 1] := haCenter;
  3.   ...
  4.   // or, shorter:
  5.   WkBkGrid.HorAlignments[1, 1, 10, 1] := haCenter;


 

 

TinyPortal © 2005-2018