StringGrid.RowCount równe ilości rekordów w tabeli

0

Mam problem z ustawieniem w StringGrid ilości wierszy odpowiadającej ilości rekordów w tabeli.
Próbowałem w ten sposób jednak zwracana ilość nie odpowiada rzeczywistości.

procedure TForm2.Button3Click(Sender: TObject);
var idx:integer;
begin
MSTable1.open;
idx := 1;
MSTable1.FetchAll;
StringGrid1.RowCount:=MSTable1.FetchRows-1 ;
while not MSTable1.eof do
begin
StringGrid1.cells[1, idx] := MSTable1.Fields[0].asString;
StringGrid1.cells[2, idx] := MSTable1.FieldByName('nazwa').asString;
MSTable1.next;
idx := idx + 1;
end;
MSTable1.Close; 
0

StringGrid1.RowCount:=1; //nagłówki pewnie też pokazujesz
while not MSTable1.eof do
begin
StringGrid1.RowCount:=StringGrid1.RowCount+1;
StringGrid1.cells[1, idx] := MSTable1.Fields[0].asString;
StringGrid1.cells[2, idx] := MSTable1.FieldByName('nazwa').asString;
MSTable1.next;
idx := idx + 1;
end;

0
idx := StringGrid1.FixedRows;
MSTable1.FetchAll;
StringGrid1.RowCount:=MSTable1.FetchRows+idx;
0

Działa po małej poprawce.

StringGrid1.RowCount:=MSTable1.FetchRows+idx-1;

Bez odjęcia jedynki pokazuje na końcu jeden pusty wiersz.

0

Tylko problem pojawił się po usunięciu kilku rekordów z tabeli. Ilość wierszy w StrigGridzie odpowiada ilości wierszy przed skasowanie z tym, że reszta jest pusta.

0

Rozwiązałem to w ten sposób:

MSTable1.open;
idx:=0;
while not MSTable1.eof do
begin
idx := idx +1;
StringGrid1.RowCount:=idx+1;
StringGrid1.cells[1, idx] := MSTable1.Fields[0].asString;
StringGrid1.cells[2, idx] := MSTable1.FieldByName('nazwa').asString;
MSTable1.next;
end;
MSTable1.Close; 

Dodałem 1 do wiersza: StringGrid1.RowCount:=idx+1;

1 użytkowników online, w tym zalogowanych: 0, gości: 1