1.放一个TCombox(cboDy)、一个StringGrid(sgdQry)至窗体,下拉框的DropDowCount>0
2.代码如下:
var
   nRow,nCol:integer;
//lost focus
procedure TfrmMain.cboDyExit(Sender: TObject);
begin
   sgdQry.Cells[nRow,nCol]:=cboDy.Text;
   cboDy.Visible:=false;
end;
//动态显示cboDy
procedure TfrmMain.sgdQrySelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
var
   rect:TRect;
begin
   with cboDy do
     begin
        rect:=sgdQry.CellRect(ACol,ARow);
        left:=rect.Left+sgdQry.left;
        top:=rect.Top+sgdQry.top;
        width:=rect.right-rect.left;
        height:=rect.Bottom-rect.top;
        visible:=true;
     end;
end;
procedure TfrmMain.sgdQryDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with sgdQry do
  begin
       if not Focused and (ACol=col)and(ARow=Row) then
       begin
          Canvas.Brush.Color:=Color;
          Canvas.FillRect(Rect);
       end;
  end;
end;