你的写法错了把 应该在SELECTCELL中写代码 如果你那样写的话 是一个CELL生成一个CHECKBOX 如果在SELECTCELL中的话,只要一个CHECKBOX ); With Sender As TStringgrid Do If (ACol = 1) and (ARow >= FixedRows) Then //在第二列显示一个ComboBox Begin //取消选中模式 perform( WM_CANCELMODE, 0, 0 ); //确定ComboBox的位置 R := CellRect( Acol, Arow ); if acol=1 then With empolyee do begin setbounds( R.left+1, R.top+1, r.right-r.left, height ); itemindex := Items.IndexOf( Cells[ acol, arow ] ); Show; BringTofront; //使得ComboBox称为输入的焦点 SetFocus; //DroppedDown := true; end; End
应该在SELECTCELL中写代码
如果你那样写的话
是一个CELL生成一个CHECKBOX
如果在SELECTCELL中的话,只要一个CHECKBOX
); With Sender As TStringgrid Do
If (ACol = 1) and (ARow >= FixedRows) Then //在第二列显示一个ComboBox
Begin
//取消选中模式
perform( WM_CANCELMODE, 0, 0 );
//确定ComboBox的位置
R := CellRect( Acol, Arow );
if acol=1 then
With empolyee do
begin
setbounds( R.left+1, R.top+1, r.right-r.left, height );
itemindex := Items.IndexOf( Cells[ acol, arow ] );
Show;
BringTofront;
//使得ComboBox称为输入的焦点
SetFocus;
//DroppedDown := true;
end;
End
首先,谢谢你的指导。我是DELPHI的初学者,常常问低级的问题,请别见笑。
我按你的指点,修改了代码,但还是无法下拉该下拉框(可以获得焦点)。同样的代码,把下拉框建立在FORM上,即可,而建立在TSTRINGGRID上却不行。这是为什么?下面是我的代码:unit Unit3;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;type
TForm3 = class(TForm)
SgDestination: TStringGrid;
CheckBox1: TCheckBox;
procedure SgDestinationSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form3: TForm3;implementation{$R *.dfm}procedure TForm3.SgDestinationSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
R : TRect;
chkstate : TComboBox;//tcheckbox;
itemindex : integer;
begin
With Sender As TStringgrid Do
If (ACol = 2) Then
Begin
chkState := TComboBox.Create(self);
chkstate.parent := sgDestination;
chkstate.Items.Add('show');
chkstate.Items.Add('noshow');
perform( WM_CANCELMODE, 0, 0 );
R := CellRect( Acol, Arow );
if acol = 2 then
With chkstate do
begin
setbounds( R.left+1, R.top+1, r.right-r.left, height );
itemindex := Items.IndexOf( Cells[ acol, arow ]);
Show;
BringTofront;
SetFocus;
// DroppedDown := true;
end;
end;end;
end.
谢谢各位!