ComponentOne Input for WinForms
Using the C1Input Controls / C1Input Controls / C1ComboBox Control Overview / Adding Items to C1ComboBox
In This Topic
    Adding Items to C1ComboBox
    In This Topic

    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

    1. On the form, right-click on the C1ComboBox control and select Edit Items. The String Collection Editor appears.
    2. 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

    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:

    1. Add the C1ComboBox control to the Form.
    2. Add a Button control to the Form.
    3. 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

    Visual Basic
    Copy Code
     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#

    C#
    Copy Code
     private void button1_Click(object sender, EventArgs e)
            {
                string[] items = { "FreeStyle Stroke", "Back Stroke", "ButterFly Stroke", "Breast Stroke"};
                c1ComboBox1.Items.AddRange(items);
            }
    1. Run your project and click on the Button.
    2. Click on the dropdown button on the C1ComboBox control and notice the string of items appear in the dropdownlist:

    combobox

    See Also