procedure TForm1.DBGrid1ColExit(Sender: TObject); begin If
DBGrid1.SelectedField.FieldName = DBComboBox1.DataField
then begin DBComboBox1.Visible := false; end; end;
6、
当DBGrid指定列获得焦点时DrawDataCell事件只是绘制单元格,并显示DBComboBox,但是DBComboBox并没有获得焦点,数据的输入还是在单元格上进行。在DBGrid1的KeyPress事件中调用SendMessage这个
Windows API函数将数据输入传输到DBComboBox上,从而达到在DBComboBox上进行数据输入。因此还要设置KeyPress事件如下:
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key:
Char); begin if (key $#@60; $#@62; 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;