Completar um StringGrid
Boa Tarde, senhores gostaria de aprender como faço para pegar os registros que tenho dentro da minha base de dados e coloca-los em um StringGrid.
Obrigado.
Obrigado.
Rscrj
Curtidas 0
Respostas
Oto Schneider
04/12/2003
Caro Rafael Cabral,
Ai vai um exemplo para se preencher um stringgrid com tres colunas lendo uma tabela com tres campos (Codigo, Nome, Endereco)
procedure PreencheGrid;
var
i: integer;
begin
i:= 0;
with Tabela do
while not eof do
begin
with StringGrid do
begin
Cells[0,i]:= IntToStr(Fieldbyname(´Codigo´).asinteger);
Cells[1,i]:= Fieldbyname(´Nome´).asstring;
Cells[2,i]:= Fieldbyname(´Endereco´).asstring;
RowCount:= i;
inc(i);
end;
next;
end;
end;
Onde Cells[Col, Lin]
Boa sorte...
Ai vai um exemplo para se preencher um stringgrid com tres colunas lendo uma tabela com tres campos (Codigo, Nome, Endereco)
procedure PreencheGrid;
var
i: integer;
begin
i:= 0;
with Tabela do
while not eof do
begin
with StringGrid do
begin
Cells[0,i]:= IntToStr(Fieldbyname(´Codigo´).asinteger);
Cells[1,i]:= Fieldbyname(´Nome´).asstring;
Cells[2,i]:= Fieldbyname(´Endereco´).asstring;
RowCount:= i;
inc(i);
end;
next;
end;
end;
Onde Cells[Col, Lin]
Boa sorte...
GOSTEI 0
Rafael Heise
04/12/2003
para todos registros e colunas...
procedure DataSetToStringGrid(aDataSet: TDataSet; aStringGrid: TStringGrid); begin var linha: integer; cont: integer; begin; linha := 0; aStringGrid.RowCount := aDataSet.RecordCount; aStringGrid.ColCount := aDataSet.FieldsCount; while not aDataSet.Eof do begin for cont := 0 to aDataSet.FieldsCount -1 do aStringGrid.[linha,cont] := aDataSet.Fields[cont].AsString; Inc(linha); aDataSet.Next; end; end;
GOSTEI 0