Consultor Eletrônico



Kbase P162193: How to populate a Windows Forms ComboBox from a database table or temp-table
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/7/2010
Status: Unverified

GOAL:

How to populate a Windows Forms ComboBox from a database table or temp-table

GOAL:

How to fill a .NET combo box from a database table or temp-table

GOAL:

How to use the System.Windows.Forms.ComboBox control with an OpenEdge database table or temp-table

FACT(s) (Environment):

Windows
OpenEdge 10.2x

FIX:

Items are added to the Windows Forms ComboBox control using the Add method of the Items property. The item to be added must be an System.Object. A CHARACTER field of a database table or temp-table may be added as a String object; other data types should be converted to Strings using their ToString method.
A FOR EACH is a good choice for obtaining the item values from table or temp-table records. because it is only necessary to go through the records once from beginning to end when the CombBox is populated. It is not necessary to use a query because forward and backward navigation is not needed.
The following example populates a ComboBox control named comboBoxSalesRep with values from the Sports2000 Salesrep table. An "All Sales Reps" item is inserted as the first item in the ComboBox, and is selected as the starting choice. Code like this would normally be included in the constructor of the form containing the ComboBox, after the call to InitializeComponent./*
Populate the sales rep combo box in the form constructor, after the combo box has been
created in InitializeComponent but before it has been displayed. Note that .NET controls are indexed beginning with 0 (zero). Make the first choice in the list "All Sales Reps" and select it by default. The rest of the list items come from the Salesrep table.
*/
comboBoxSalesRep:Items:Add('All Sales Reps'). /* list item 0 is no filter */
FOR EACH Salesrep: /* list items 1 and greater from Salesrep table */
comboBoxSalesRep:Items:Add(Salesrep.SalesRep).
END.
comboBoxSalesRep:SelectedIndex = 0. /* by default do not filter */