类似MSSQL创建表差不多的功能,就是允许输入一行,一旦输入某一行后,自动添加下一个空白行。同时支持选中行删除。
这是困扰我两天的难题,最后还是到论坛发帖求助,求一解决方案
procedure TForm1.FormCreate(Sender: TObject);
begin
Init;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (acol=3) and (arow>=1) then
begin
if not (gdFixed in State) then
with TStringGrid(Sender).Canvas do
begin
brush.Color:=clWindow;
FillRect(Rect);
if StringGrid1.Cells[ACol,ARow]=’yes’ then
Draw( (rect.right + rect.left – FCheck.width) div 2,
(rect.bottom + rect.top – FCheck.height) div 2,
FCheck )
else
Draw( (rect.right + rect.left – FCheck.width) div 2,
(rect.bottom + rect.top – FCheck.height) div 2,
FNoCheck );
end;
end;
end;
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
if (StringGrid1.col=3) and (StringGrid1.row>=1) then
begin
StringGrid1.Options:=StringGrid1.Options-[goEditing] ;
if StringGrid1.Cells[StringGrid1.col,StringGrid1.row]=’yes’ then
StringGrid1.Cells[StringGrid1.col,StringGrid1.row]:=’no’
else
StringGrid1.Cells[StringGrid1.col,StringGrid1.row]:=’yes’;
end else
StringGrid1.Options:=StringGrid1.Options+[goEditing] ;
end;
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key=vk_down) and ( StringGrid1.Row=StringGrid1.RowCount-1) then
addgrid;
end;
procedure TForm1.StringGrid1DblClick(Sender: TObject);
begin
DeleteRow( StringGrid1.Row);
end;
end.