cxLookupComboBox 组件的应用

1.Setting up a

The LookupComboBox editor is capable of displaying dataset values. Values are displayed within the edit region of an editor and its dropdown window (which displays data in a tabular manner). To establish a connection between the LookupComboBox and the dataset being displayed within the editor, a user needs to specify the property value. This property identifies a instance connected to the dataset (for instance, a object). In this example, the LookupComboBox will be connected to the Customer table from the DBDEMOS database shipped with Borland Delphi or C++ Builder. The following image demonstrates how to connect a LookupComboBox to a data source at design time:


The following code line performs the same actions:

//Delphi

cxLookupComboBox1.Properties.ListSource := DataSource1;

//C++ Builder

cxLookupComboBox1->Properties->ListSource = DataSource1;

After that, you must choose the dataset fields to display within the LookupComboBox by setting the property value. This property contains the names of dataset fields and they are separated by semicolon(s). The following image demonstrates how to set up the property value at design time:


The following code sets the property value:

//DelphicxLookupComboBox1.Properties.ListSource := DataSource1; cxLookupComboBox1.Properties.ListFieldNames := 'Company;Addr1';//C++ BuildercxLookupComboBox1->Properties->ListSource = DataSource1; cxLookupComboBox1->Properties->ListFieldNames = "Company;Addr1";

Note: On adding a dataset field to the property value, a column is added to the collection. Use the list columns collection editor at design time to edit this collection (or modify the property value):


This editor allows you to set up different options for the dropdown list columns of a lookup combo box. The main property of each lookup combo box column is the property, which specifies the dataset field displayed within a specific column. The and properties determine the display order of a specific column. The property is used to specify the repository item to use as an editor of a specific column抯 contents. For instance, a user can assign a control to represent the values when the ListSource field contains Boolean data. Other properties define the visual representation of columns within the editor dropdown (, , and properties).

The next important thing is to specify the key field used to identify records of the dataset to be displayed within the editor dropdown. The name of the key field must be assigned to the property. The design time approach is demonstrated on the following image:


The following code shoes how to set the property value programmatically:

//Delphi

cxLookupComboBox1.Properties.ListSource := DataSource1;

cxLookupComboBox1.Properties.ListFieldNames := 'Company;Addr1';cxLookupComboBox1.Properties.KeyFieldNames := 'CustNo;Addr1'; 取KeyFieldNames'CustNo'值: Memo1.Text:=VarToStr(cxLookupComboBox1.EditValue[0]);

取KeyFieldNames'Addr1'值:

Memo1.Text:=VarToStr(cxLookupComboBox1.EditValue[1]);

设置宽度: cxLookupComboBox1.Properties.DropDownWidth:=1000;

cbbDeptCode.Properties.DataController.Values[cbbDeptCode.Properties.DataController.FindRecordIndexByKey(cbbDeptCode.EditValue),1]);

就是这个语句,最后面的1就是第二列,从Properties.ListColumns里面取的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值