如何从 TcxDBLookupComboBox 组件中获取 select 值?
How to select value from TcxDBLookupComboBox component?
我正在使用 Delphi 10.3 Rio 和 DevExpress 18.1.6 库。
在我的项目中,我有 TcxDBLookupComboBox
个组件。
如您在此处看到的那样,我填充了该组合框
但是当我select其中一个值并点击它时,没有任何反应。
我检查了该组件的属性,但找不到任何可以帮助我的东西。
知道如何实现吗?
如果您遇到这种情况,则表明您的表单配置不正确。
下面是示例项目的摘录,其中 "self contained"
它在 Form 的 FormCreate 事件中的代码中创建数据并查找数据。
它完全正常工作 - 当我单击 DBLookUpcombo 列表时
所选列表条目中的值立即出现在 Value
ClientDataSet1
的字段
procedure TForm1.FormCreate(Sender: TObject);
var
AField : TField;
begin
// First create some dataset fields
AField := TIntegerField.Create(Self);
AField.FieldName := 'ID';
AField.FieldKind := fkData;
AField.DataSet := ClientDataSet1;
AField := TStringField.Create(Self);
AField.FieldName := 'Value';
AField.FieldKind := fkData;
AField.Size := 40;
AField.DataSet := ClientDataSet1;
ClientDataSet1.CreateDataSet;
ClientDataSet1.InsertRecord([1, 'SomeValue']);
AField := TStringField.Create(Self);
AField.FieldName := 'luValue';
AField.FieldKind := fkData;
AField.Size := 40;
AField.DataSet := cdsLU;
cdsLU.CreateDataSet;
cdsLU.InsertRecord(['One']);
cdsLU.InsertRecord(['Two']);
cdsLU.InsertRecord(['Three']);
DBLookupComboBox1.DataSource := DataSource1;
DBLookupComboBox1.DataField := 'Value';
DBLookupComboBox1.KeyField := 'luValue';
DBLookupComboBox1.ListField := 'luValue';
DBLookupComboBox1.ListSource := DataSource2;
end;
TForm1 的余数:
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
ClientDataSet1: TClientDataSet;
DBLookupComboBox1: TDBLookupComboBox; // or TcxDBLookupComboBox
cdsLU: TClientDataSet;
DataSource2: TDataSource;
procedure FormCreate(Sender: TObject);
public
end;
我正在使用 Delphi 10.3 Rio 和 DevExpress 18.1.6 库。
在我的项目中,我有 TcxDBLookupComboBox
个组件。
如您在此处看到的那样,我填充了该组合框
但是当我select其中一个值并点击它时,没有任何反应。
我检查了该组件的属性,但找不到任何可以帮助我的东西。
知道如何实现吗?
如果您遇到这种情况,则表明您的表单配置不正确。
下面是示例项目的摘录,其中 "self contained"
它在 Form 的 FormCreate 事件中的代码中创建数据并查找数据。
它完全正常工作 - 当我单击 DBLookUpcombo 列表时
所选列表条目中的值立即出现在 Value
ClientDataSet1
procedure TForm1.FormCreate(Sender: TObject);
var
AField : TField;
begin
// First create some dataset fields
AField := TIntegerField.Create(Self);
AField.FieldName := 'ID';
AField.FieldKind := fkData;
AField.DataSet := ClientDataSet1;
AField := TStringField.Create(Self);
AField.FieldName := 'Value';
AField.FieldKind := fkData;
AField.Size := 40;
AField.DataSet := ClientDataSet1;
ClientDataSet1.CreateDataSet;
ClientDataSet1.InsertRecord([1, 'SomeValue']);
AField := TStringField.Create(Self);
AField.FieldName := 'luValue';
AField.FieldKind := fkData;
AField.Size := 40;
AField.DataSet := cdsLU;
cdsLU.CreateDataSet;
cdsLU.InsertRecord(['One']);
cdsLU.InsertRecord(['Two']);
cdsLU.InsertRecord(['Three']);
DBLookupComboBox1.DataSource := DataSource1;
DBLookupComboBox1.DataField := 'Value';
DBLookupComboBox1.KeyField := 'luValue';
DBLookupComboBox1.ListField := 'luValue';
DBLookupComboBox1.ListSource := DataSource2;
end;
TForm1 的余数:
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
ClientDataSet1: TClientDataSet;
DBLookupComboBox1: TDBLookupComboBox; // or TcxDBLookupComboBox
cdsLU: TClientDataSet;
DataSource2: TDataSource;
procedure FormCreate(Sender: TObject);
public
end;