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
Visual Basic |
Copy Code
|
---|---|
c1ComboBox1.Items.Add("Pittsburgh") |
To write code in C#
C# |
Copy Code
|
---|---|
c1ComboBox1.Items.Add("Pittsburgh"); |
To Add Items Using the String Collection Editor
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
Visual Basic |
Copy Code
|
---|---|
c1ComboBox1.Items.Insert(4, "Chicago") |
To write code in C#
C# |
Copy Code
|
---|---|
c1ComboBox1.Items.Insert(4, "Chicago"); |
To Pass an Array through Strings
To pass an array through strings, complete the following:
To write code in Visual Basic
Visual Basic Copy CodePrivate 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 SubC#
C# Copy Codeprivate void button1_Click(object sender, EventArgs e)
{
string[] items = { "FreeStyle Stroke", "Back Stroke", "ButterFly Stroke", "Breast Stroke"};
c1ComboBox1.Items.AddRange(items);
}