在dbgrid DrawDataCell事件照如下方法: begin if (gdFocused in State) then begin if (Field.FieldName = DBLookupComboBox1.DataField ) then begin DBLookupComboBox1.Left :=Rect.Left + DBGrid2.Left; DBLookupComboBox1.Top := Rect.Top + DBGrid2.top; DBLookupComboBox1.Width := Rect.Right - Rect.Left; DBLookupComboBox1.Height := Rect.Bottom - Rect.Top; DBLookupComboBox1.Visible := True; end; end;ColExit 事件 begin If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then begin DBComboBox1.Visible := false; end; end;
外嵌较简单,就是把DBComboBox“放”在对应的Cell中;
内嵌是指继承TDBGrid的TInplaceEditor,把要用的类型加到Columns中,你可以看看DBGrid是怎样实现Picklist,跟着它作就可以了。
begin
if (gdFocused in State) then
begin
if (Field.FieldName = DBLookupComboBox1.DataField ) then
begin
DBLookupComboBox1.Left :=Rect.Left + DBGrid2.Left;
DBLookupComboBox1.Top := Rect.Top + DBGrid2.top;
DBLookupComboBox1.Width := Rect.Right - Rect.Left;
DBLookupComboBox1.Height := Rect.Bottom - Rect.Top;
DBLookupComboBox1.Visible := True;
end;
end;ColExit 事件
begin
If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then
begin
DBComboBox1.Visible := false;
end;
end;