给你一段代码:
procedure TFrmExchOption.DBGrid1DrawDataCell(Sender: TObject;
const Rect: TRect; Field: TField; State: TGridDrawState);
begin
if (gdFocused in State) then
if (Field.FieldName = DBComboBox1.DataField) then
begin
DBComboBox1.Left := Rect.Left + DBGrid1.Left;
DBComboBox1.Top := Rect.Top + DBGrid1.top+panel2.Top;
DBComboBox1.Width := Rect.Right - Rect.Left+4;
DBComboBox1.Visible := True;
end
end;
procedure TFrmExchOption.DBGrid1ColExit(Sender: TObject);
begin
if DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then
DBComboBox1.Visible := false;
end;
procedure TFrmExchOption.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
//当DBComboBox1在cell中时,在cell中输入的键传给DBComboBox1
if (key <> chr(9)) then
begin
if (DBGrid1.SelectedField.FieldName = DBComboBox1.DataField)
then
begin
DBComboBox1.SetFocus;
SendMessage(DBComboBox1.Handle, WM_Char, word(Key), 0);
end;
end;
end;