Evalua la propiedad RowCount antes de intentar moverte a la primera (imprimela en pantalla)
Yo uso este codigo y si puedo moverme a la primer fila:
Código Delphi
[-]
TForm4 = class(TForm)
StringGrid1: TStringGrid;
Panel1: TPanel;
btnCargarGrid: TButton;
btnFiltrarGrid: TButton;
procedure btnCargarGridClick(Sender: TObject);
procedure btnFiltrarGridClick(Sender: TObject);
private
procedure CargarGrid(Items: TStrings);
procedure LimpiarGrid;
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.btnCargarGridClick(Sender: TObject);
var
Items: TStrings;
begin
LimpiarGrid;
Items := TStringList.Create;
try
Items.CommaText := 'Juan, Pedro, Marcos, Agustin, Daniel, German, Federico';
CargarGrid(Items);
finally
Items.Free;
end;
end;
procedure TForm4.btnFiltrarGridClick(Sender: TObject);
var
Items: TStrings;
begin
LimpiarGrid;
Items := TStringList.Create;
try
Items.CommaText := 'Juan, Pedro, Federico';
CargarGrid(Items);
StringGrid1.Row := 1;
finally
Items.Free;
end;
end;
procedure TForm4.CargarGrid(Items: TStrings);
var
I: Integer;
begin
StringGrid1.RowCount := Items.Count + 1;
for I := 0 to Items.Count - 1 do
begin
StringGrid1.Cells[0, I+1] := Items[i];
StringGrid1.Cells[1, I+1] := Items[i];
StringGrid1.Cells[2, I+1] := Items[i];
StringGrid1.Cells[3, I+1] := Items[i];
end;
end;
procedure TForm4.LimpiarGrid;
var
I, J: Integer;
begin
for I := 0 to StringGrid1.RowCount - 1 do
for J := 0 to StringGrid1.ColCount - 1 do
StringGrid1.Cells[I, J] := EmptyStr;
end;