我就是这样做的
反应很快 很好用
//该过程,在StringGrid上动态创建ComboBOx,并初始化
procedure TDlgProjInput2.CreateComboBox(Rownum,Colnum,initIndex:integer;
initValue:string);
var
itemList:TstringList;
i:integer;
begin
itemList:=TstringList.Create;
with StringGrid1 do
begin
Objects[Colnum,Rownum]:=TComboBox.Create(Self);
with Objects[Colnum,Rownum] as TComboBox do
begin
Parent := Self;
Windows.SetParent((Objects[Colnum,Rownum] as TComboBox).Handle, stringGrid1.Handle);
//width:=65;
//Height:=24;
Font.Size:=11;
Font.Color:=clBlue;
visible:=False;
style:=csDropDownList;
itemList.CommaText:=initValue;
for i:=0 to itemList.Count-1 do
begin
Items.Add(itemList);
end;
ItemIndex:=initIndex;
Cells[Colnum,Rownum]:=Trim(text);
Onchange:=ComboBoxChange;
end;
end;
itemList.Free;
end;