procedure TForm1.FormCreate(Sender: TObject);
begin
combobox1.visible := false;
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,ARow: Integer; var CanSelect: Boolean);
var
R: TRect;
org: TPoint;
begin
With Sender As TStringgrid Do
If (ACol = 2) and (ARow >= FixedRows) Then //在第二列显示一个ComboBox
Begin
perform( WM_CANCELMODE, 0, 0 );
R := CellRect( Acol, Arow );
org:= Self.ScreenToClient( ClientToScreen( R.topleft ));
With combobox1 do
begin
setbounds( org.X, org.Y, r.right-r.left, height );
itemindex := Items.IndexOf( Cells[ acol, arow ] );
Show;
BringTofront;
SetFocus;
DroppedDown := true;
end;
End;
end;
procedure TForm1.ComboBox1Exit(Sender: TObject);
begin
with sender as TCombobox do
begin
hide;
if itemindex >= 0 then
with stringgrid1 do
cells[ col, row ] := items[itemindex];
end;
End;