« on: September 12, 2016, 10:57:11 am »
Hi all,
I’m trying to populate a StringGrid from a TstringList, but I don’t want to fill the first column and row.
Those I want to keep for header and row index.
procedure tfrmMain.PopulateStringGrid;
var
TextFile, Line: TStringList;
Row, Col: Integer;
begin
grd_list.RowCount := 0;//clear any previous data
TextFile := TStringList.Create;
try
Line := TStringList.Create;
try
Line.Delimiter := ' ';
TextFile.LoadFromFile(C_FNAME);
grd_list.RowCount := TextFile.Count;
for Row := 0 to TextFile.Count-1 do
begin
Line.DelimitedText := TextFile[Row];
for Col := 0 to grd_list.ColCount-1 do
if Col<Line.Count then
grd_list.Cells[Col, Row] := Line[Col]
else
grd_list.Cells[Col, Row] := 'N/A';
end;
finally
Line.Free;
end;
finally
TextFile.Free;
end;
end;

Logged
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0