[]
You can easily add items to C1ComboBox programmatically using the Add method or you can add them at design time through the String Collection Editor. If you have more than one item, the Add method will add the new item(s) in the next position. If you need to add an item or object at a specific position in the list you can use the Insert method. An entire array can be added to the ComboBox by using the AddRange method to add the object or string of items to the C1ComboBox.
To Add Items Programmatically
To add items to the C1ComboBox using the Add method of the C1ComboBox class. The collection is referenced using the Items property.
To write code in Visual Basic
c1ComboBox1.Items.Add("Pittsburgh")
To write code in C#
c1ComboBox1.Items.Add("Pittsburgh");
To Add Items Using the String Collection Editor
On the form, right-click on the C1ComboBox control and select Edit Items. The String Collection Editor appears.
In the String Collection Editor, enter the string and then press Enter to add the next string in position.
To Insert the String or Object at the Desired Position
The following example inserts the string, Chicago, in the fifth position:
To write code in Visual Basic
c1ComboBox1.Items.Insert(4, "Chicago")
To write code in C#
c1ComboBox1.Items.Insert(4, "Chicago");
To Pass an Array through Strings
To pass an array through strings, complete the following:
Add the C1ComboBox control to the Form.
Add a Button control to the Form.
Create the following Button_Click event handler and add the following code to pass the array through strings to the C1ComboBox:
To write code in Visual Basic
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim items As String() = {"FreeStyle Stroke", "Back Stroke", "ButterFly Stroke", "Breast Stroke"}
C1ComboBox1.Items.AddRange(items)
End Sub
C#
private void button1_Click(object sender, EventArgs e)
{
string[] items = { "FreeStyle Stroke", "Back Stroke", "ButterFly Stroke", "Breast Stroke"};
c1ComboBox1.Items.AddRange(items);
}
Run your project and click on the Button.
Click on the dropdown button on the C1ComboBox control and notice the string of items appear in the dropdownlist: