可以在cell里面用edit框来编辑数据,
程序大抵如下,还需你进一步完善,
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
x,y:integer;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Color:=clBlue;
Edit1.Visible:=False;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
x:=aCol;
y:=aRow;
if (gdFocused in State) then
begin
Edit1.Text := StringGrid1.Cells[x,y];
Edit1.Left := Rect.Left + StringGrid1.Left + 2;
Edit1.Top := Rect.Top + StringGrid1.top + 2;
Edit1.Width := Rect.Right - Rect.Left;
Edit1.Height := Rect.Bottom - Rect.Top;
Edit1.Visible := True;
end else
begin
Edit1.Visible:=False;
end;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
//判断数据有效性
StringGrid1.Cells[x,y]:=Edit1.Text;
end;
end.