读书人

stringgrid 控件 rowcount 的有关问题

发布时间: 2012-03-14 12:01:13 作者: rapoo

stringgrid 控件 rowcount 的问题!
procedure TForm1.Button1Click(Sender: TObject);
begin
stringgrid3.RowCount:=stringgrid3.RowCount+1;
stringgrid3.Cells[0,stringgrid3.RowCount]:=adoquery1.fieldbynam('SPMC').AsString;
stringgrid3.Cells[1,stringgrid3.RowCount]:=adoquery1.fieldbyname('DW').AsString;
stringgrid3.Cells[2,stringgrid3.RowCount]:=edit21.Text;
stringgrid3.Cells[3,stringgrid3.RowCount]:=edit22.Text;
stringgrid3.Cells[4,stringgrid3.RowCount]:=inttostr(j);
end;
end.

我想实现 点击按钮 增加行 然后赋值, 但是 rowcount 不能为0,这让我不知道怎么办了!谁知道怎么解决麻烦给我说下!

[解决办法]
procedure TForm1.Button2Click(Sender: TObject);
begin
stringgrid1.RowCount:=stringgrid1.RowCount+1;
stringgrid1.Cells[0,stringgrid1.RowCount-1]:='aaa';
stringgrid1.Cells[1,stringgrid1.RowCount-1]:='bbb';
stringgrid1.Cells[2,stringgrid1.RowCount-1]:='ccc';
stringgrid1.Cells[3,stringgrid1.RowCount-1]:='ddd';
stringgrid1.Cells[4,stringgrid1.RowCount-1]:='eee';
end;

行号是从0开始的,所以最大行的行号是rowcount-1

读书人网 >.NET

热点推荐