Recent

Author Topic: Identification of TGridColumn fails after CSV file loaded into TStringGrid  (Read 758 times)

dgrhoads

  • New Member
  • *
  • Posts: 34
The following code fails when the StringGrid is loaded from a CSV file.
It does not fail when StringGrid is created by manually copying the contents of another StringGrid.  By manually, I means use of the command StringGrid.Columns.Add to explicitly add columns.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid2Selection(Sender: TObject; aCol, aRow: Integer);
  2. // Select cell from sg2.
  3. begin
  4.   aInt := sg2.Columns.Items[aCol].Index;  
  5.   ShowMessage ('sg2 column index: '+IntToStr(aInt));
  6.  
  7. end;  
  8.  

One of the confusing elements of this problem is that StringGrid1.ColCount and ..RowCount return the values expected from the CSV file. 

Attached is a program which demonstrates this problem.  A CSV file is included.

dsiders

  • Hero Member
  • *****
  • Posts: 1084
The following code fails when the StringGrid is loaded from a CSV file.
It does not fail when StringGrid is created by manually copying the contents of another StringGrid.  By manually, I means use of the command StringGrid.Columns.Add to explicitly add columns.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid2Selection(Sender: TObject; aCol, aRow: Integer);
  2. // Select cell from sg2.
  3. begin
  4.   aInt := sg2.Columns.Items[aCol].Index;  
  5.   ShowMessage ('sg2 column index: '+IntToStr(aInt));
  6.  
  7. end;  
  8.  

One of the confusing elements of this problem is that StringGrid1.ColCount and ..RowCount return the values expected from the CSV file. 

Attached is a program which demonstrates this problem.  A CSV file is included.

LoadFromCSVFile does not update the items in the Columns collection if it is not already Enabled (at least one visible column exists in the collection).
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

 

TinyPortal © 2005-2018