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.
procedure TForm1.StringGrid2Selection(Sender: TObject; aCol, aRow: Integer);
// Select cell from sg2.
begin
aInt := sg2.Columns.Items[aCol].Index;
ShowMessage ('sg2 column index: '+IntToStr(aInt));
end;
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.