has anyone managed to get a DBLookupComboBox to work with a DBCtrlGrid?
a pre filled in DBComboBox works ok, but it dose not work to well for lookup tables;
delphi 7
has anyone managed to get a DBLookupComboBox to work with a DBCtrlGrid?
a pre filled in DBComboBox works ok, but it dose not work to well for lookup tables;
delphi 7
I just added a TDBLookupCombo to a TDBCtrlGrid. When I tried to set the ListSource, I got the error:
Operation not allowed in a DBCtrlGrid.
Therefore it appears that this is explicitly forbidden in Delphi and so you won't be able to do it.
Well, I don't understand why it is forbidden action in Delphi, but i've managed to create my own lookup-combo-box component with csReplicatable flag in ComponentStyle and it works!
Its not thoroughly tested, but in my app it works without problems.
Being quite reticent to alter/maintain altered VCL/RTL code, I found another way. Declare the following in the Interface of your unit:
interface
uses ... ;
type Tdbp = class(TDBCtrlGrid); type tdbl = class(TDBLookupControl);
type TForm4 = class(TForm) ... DBCtrlGrid1: TDBCtrlGrid; ... private ... function FindLCB(DataFieldName: String): TDBLookupComboBox; procedure FixDBLookupDataLinks; public ... end;
...and in your implementation:
implementation
procedure TForm4.FormCreate(Sender: TObject); begin ... DBCtrlGrid1.DataSource := DataSource1; FixDBLookupDataLinks; end;
procedure TForm4.FixDBLookupDataLinks; var lcb: TDBLookupComboBox; I,n: Integer; MyDataLink: TDataLink; ctl: TControl; dbp: Tdbctrlpanel; begin dbp := Tdbp(DBControlGrid1).Panel; for n := 0 to Pred(dbp.ControlCount) do begin ctl := dbp.Controls[n]; if ctl.ClassType = TDBLookupComboBox then begin lcb := TDBLookupComboBox(ctl); lcb.ControlStyle := lcb.ControlStyle + [csReplicatable]; TDBL(lcb).ListLink.DataSourceFixed := False; for I := 0 to Pred(lcb.ControlCount) do begin if lcb.Controls[I] is TPopupDataList then begin TDBL(lcb).ListLink.DataSourceFixed := False; TDBL(lcb).DataLink.DataSourceFixed := False; MyDataLink := TDataLink(lcb.Controls[I].Perform(CM_GETDATALINK, 0, 0)); if MyDataLink <> nil then MyDataLink.DataSourceFixed := False; MyDataLink.DataSource := nil; end; end; end; end; end;
function TForm4.FindLCB(DataFieldName: String): TDBLookupComboBox; var i: Integer; begin Result := Nil; for i := 0 to Pred(ControlCount) do if Controls[i].ClassType = TDBLookupComboBox then if TDBLookupComboBox(Controls[i]).DataField = DataFieldName then begin Result := TDBLookupComboBox(Controls[i]); Break; end; end;