如何使用dbstringgrid进行动态插入(50分)

  • 主题发起人 主题发起人 yh11
  • 开始时间 开始时间
unit Unit1;

interface

uses
Windows, Messages,stdctrls, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids;

type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public

end;

var
Form1: TForm1;
i,j:integer;
var testcombo:Tcombobox;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
testcombo:=Tcombobox.create(self);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
testcombo.Free;
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
i:=x div stringgrid1.defaultcolwidth;
j:=y div stringgrid1.defaultrowheight;
testcombo.parent:=self;
testcombo.left:=stringgrid1.left+i*(stringgrid1.defaultcolwidth+2);
testcombo.top:=stringgrid1.top+j*(stringgrid1.defaultrowheight+2);
testcombo.width:=stringgrid1.DefaultColWidth;
testcombo.Height:=stringgrid1.gridHeight;
testcombo.font:=stringgrid1.font;
testcombo.Items.Clear;
testcombo.text:='未知';
testcombo.Items.add('1111');
testcombo.Items.add('2222');
testcombo.Items.add('3333');
testcombo.Items.add('4444');
end;

end.
 
接受答案了.
 
后退
顶部