cxLookupComboBox 组件的应用

来源:互联网 发布:网页游戏的数据库修改 编辑:程序博客网 时间:2024/05/19 19:35

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里面取的。