Home Forums WinForms controls Other WinForms controls Populate ComboBox Reply To: Populate ComboBox

User (Old forums)
Member
Post count: 23064

Follow up to my own post, now that I’ve found the answers.

1) To populate a static list at design time:

Click on ComboBox, and a dropdown saying “(New ComboBoxItem)” appears. Double-click on that to create new Item. Type in value in the “Text” field of the Properties screen.

2) To populate a static list at run time:

Use the Items.Add method of the control, like this:

MyComboCtl.Items.Add (“MyValue1”)
MyComboCtl.Items.Add (“MyValue2”)

3) To populate a dynamic (data-bound) list:

You can’t. According to Xceed’s technical support, the ComboBox “control was not designed to be data bound.” As a workaround, you can read the data yourself, then use Items.Add to build the control, something like this (some details on creating a data connection have been left out):

myCmd = New SqlCommand(“SELECT <FieldName> FROM <TableName>”, myConnection)
myReader = myCmd.ExecuteReader
Do While myReader.Read
MyComboCtl.Items.Add (myReader(<FieldName>)
Loop

Imported from legacy forums. Posted by AlphaGuys (had 3140 views)