What am I doing wrong here. I want to use a TDBLookupComboBox as an in place editor in a TDBAdvCardList but it doesn't update the field when I select a new value from the drop down list.
nit AdvCardListDBLookupComboLinks;
interface
uses
Classes, Vcl.DBCtrls, Data.Db, Controls, AdvCardList;
type
{ TAdvCardListDBLookupComboBoxLink }
TAdvCardListDBLookupComboBoxLink = class(TCardListEditLink)
private
FDBLookupComboBox: TDBLookupComboBox;
FDataSource: TDataSource;
FListSource: TDataSource;
FDataField: string;
FKeyField: String;
FListField: String;
FDropDownWidth : Integer;
public
constructor Create(AOwner: TComponent); override;
function CreateControl: TWinControl; override;
procedure SetProperties; override;
procedure SetSelection(SelStart, SelLength: integer); override;
procedure SetFocus; override;
procedure ValueToControl(value: variant); override;
function ControlToValue: variant; override;
published
property DataSource: TDataSource read FDataSource write FDataSource;
property ListSource: TDataSource read FListSource write FListSource;
property DataField: String read FDataField write FDataField;
property KeyField: String read FKeyField write FKeyField;
property ListField: string read FListField write FListField;
property DropdownWidth: Integer read FDropDownWidth write FDropDownWidth;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('TMS CardList', [TAdvCardListDBLookupComboBoxLink]);
end;
{ TAdvCardListDBLookupComboBoxLink }
constructor TAdvCardListDBLookupComboBoxLink.Create(AOwner: TComponent);
begin
inherited;
//FEditorEnabled := true;
end;
function TAdvCardListDBLookupComboBoxLink.CreateControl: TWinControl;
begin
FDBLookupComboBox := TDBLookupComboBox.Create(nil);
Result := FDBLookupComboBox;
end;
procedure TAdvCardListDBLookupComboBoxLink.SetProperties;
begin
inherited;
FDBLookupComboBox.OnKeyDown := ControlKeyDown;
FDBLookupComboBox.DataSource:= FDataSource;
FDBLookupComboBox.ListSource:= FListSource;
FDBLookupComboBox.DataField:= FDataField;
FDBLookupComboBox.KeyField:= FKeyField;
FDBLookupComboBox.ListField:= FListField;
FDBLookupComboBox.Visible := true;
end;
function TAdvCardListDBLookupComboBoxLink.ControlToValue: variant;
begin
{Nothing to do? should get value from datasource}
//Result := FDBLookupComboBox.KeyValue;
end;
procedure TAdvCardListDBLookupComboBoxLink.SetSelection(SelStart, SelLength: integer);
begin
{No need to set the selection}
end;
procedure TAdvCardListDBLookupComboBoxLink.SetFocus;
begin
FDBLookupComboBox.SetFocus;
end;
procedure TAdvCardListDBLookupComboBoxLink.ValueToControl(value: variant);
begin
{Do I need to do anything here? Shouldn't it just follow the datasource in the DBCardList?}
// FDBLookupComboBox.Text := value;
end;
end.
tms_Nancy
(tms Nancy)
February 21, 2012, 6:31am
2
Please contact us by email and include a ready to run sample project in attachment so we can investigate this.
Please implement the ControlToValue method. It should return the new value of the inplace editor.