可試試:
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject;
const Rect: TRect;
Field: TField;
State: TGridDrawState);
begin
if (gdFocused in State) then
if field.FullName='state' then
//假設字段名為'state'
begin
DBLookupComboBox1.Visible:=true;
DBLookupComboBox1.Parent:=dbgrid1;
DBLookupComboBox1.Left:=rect.Left;
DBLookupComboBox1.Top:=rect.Top;
DBLookupComboBox1.Width:=rect.Right-rect.Left;
DBLookupComboBox1.Height:=rect.Bottom-rect.Top;
end;
dbgrid1.DefaultDrawDataCell(rect,field,state);
end;
procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
if dbgrid1.SelectedField.FullName<>'state' then
DBLookupComboBox1.Visible:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
dbgrid1.Columns.State:=csdefault;
DBLookupComboBox1.Visible:=false;
end;