procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if gdfocused in state then
begin
if column.FieldName='xxx' then //xxx为你要让combobox显示的那列的字段名
begin
ComboBox1.Left:=rect.Left+form1.DBGrid1.Left;
ComboBox1.Top:=rect.Top+form1.DBGrid1.Top;
ComboBox1.Width:=rect.Right-rect.Left;
ComboBox1.Height:=rect.Bottom-rect.Top;
ComboBox1.Visible:=true;
end;
end;
end;
搂主,换个角度去做,试一下
With adoquery1 do//下拉框里添加产品型号
begin
Active:=False;
sql.clear;
sql.add('Select DBGRID里的列名 from 与DBGRID相关的表');
Open;
While not Eof do
begin
Combobox1.Items.Add(fieldvalues['列名'].asstring);