type
TMyGrid = class(TStringgrid);
之后,删除时:你可以这样写:
TMyGrid(Grid).DeleteRow(Grid.Row); //Grid为你的StringGrid控件
说明:DeleteRow方法是TCustomGrid类申明的protected方法,可以删除表格中的一行;而TStringGrid没有将这一方法公开出来(意味着其他类将无法访问),所以你只需要定义一个从TStringGrid类继承的新类就可以了。
这个好像有点问题,下面的这个是可以:
procedure TForm1.deleteClick(Sender: TObject);
var
i_row,j_col:integer;
begin
stringgrid1.Rows[stringgrid1.row].Clear;
for j_col:=0 to stringgrid1.colcount do
for i_row:=stringgrid1.Row to stringgrid1.rowcount-1 do
stringgrid1.cells[j_col,i_row]:=stringgrid1.cells[j_col,i_row+1];
stringgrid1.RowCount:=stringgrid1.RowCount-1;
stringgrid1.Refresh;
end;
控制edit中只能输入数字??
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8,‘.’, #13]) then
begin
Key := #0;
ShowMessage('只能输入数字');
end;
end;
stringgrid的列隐藏通过 grdView.ColWidths[col]:=0; //列隐藏 col指所在的列
StringGrid .ColCount :=10;
StringGrid .Cells[0,0]:='材料编号';
StringGrid .Cells[1,0]:='供应商';
StringGrid .ColWidths[0]:=0; //列隐藏