Recent

Author Topic: A problem with alignment of a column of a StringGrid.  (Read 1208 times)

Jvan

  • Full Member
  • ***
  • Posts: 181
A problem with alignment of a column of a StringGrid.
« on: August 26, 2020, 12:13:19 am »
I have a StringGrid with the column 1 centered.

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.myGridPrepareCanvas(sender: TObject; aCol,
  2.   aRow: Integer; aState: TGridDrawState);
  3. var
  4.   MyTextStyle: TTextStyle;
  5. begin
  6.   if (aRow >= myGrid.FixedRows) then begin
  7.     if (aCol = 1) then begin
  8.       MyTextStyle.Alignment := taCenter;
  9.       myGrid.Canvas.TextStyle := MyTextStyle;
  10.  
  11.     end else if (aCol = 4) then begin
  12.       MyTextStyle.Alignment := taRightJustify;
  13.       myGrid.Canvas.TextStyle := MyTextStyle;
  14.     end;
  15.   end;
  16. end;
  17.  

That grid has only 1 row, the header. The user add new rows with data. The column 1 contains the number of the new row: '001', '002', etc. and at times '00+'. But when a row with column 1 of '00+' is added, so the grid shows '+00' instead. In order to correct this I changed '00+' to '[00+]', but the error continues, the grid shows me '[+00]'. But numbers ar showed correctly: '001', '002', etc.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.btnAddFilaClick(Sender: TObject);
  2. begin
  3.   With myGrid do
  4.   begin
  5.     RowCount := RowCount + 1;
  6.     Cells[1, 1] := '[00+]';
  7.     Cells[2, 1] := Edit1.Text;
  8.     Cells[3, 1] := Edit2.Text;
  9.   end;
  10. end;
  11.  

wp

  • Hero Member
  • *****
  • Posts: 13266
Re: A problem with alignment of a column of a StringGrid.
« Reply #1 on: August 26, 2020, 12:48:47 am »
when a row with column 1 of '00+' is added, so the grid shows '+00' instead.
This is because of your uninitialized TextStyle record (see the other thread) the RIghtToLeft element for inverse text direction seems to be set by incidence.

Jvan

  • Full Member
  • ***
  • Posts: 181
Re: A problem with alignment of a column of a StringGrid.
« Reply #2 on: August 26, 2020, 01:05:52 am »
Thanks.

 

TinyPortal © 2005-2018