How to add ComboBox Items Dynamically

Let's say, you have a WPF ComboBox and its ID (Name or x:Name) is ComboBox1.

You can add ComboBox items at design time using ComboBoxItem element as following.

<ComboBox x:Name="ComboBox1" Width="250" Height="30"
          Canvas.Top="50" Canvas.Left="10">                     
    <ComboBoxItem Name="cbi1">C# Corner</ComboBoxItem>
    <ComboBoxItem Name="cbi2">VB.NET Heaven</ComboBoxItem>
    <ComboBoxItem Name="cbi3">MSDN</ComboBoxItem>
</ComboBox>

But say you are not sure what items you want to add to the ComboBox, then you will need to add items at run-time. You can do this by using ComboBox.Items.Add method.

The following code adds four items to a ComboBox.


ComboBox1.Items.Add("C# Corner");
ComboBox1.Items.Add("VB.NET Heaven");
ComboBox1.Items.Add("MSDN");
ComboBox1.Items.Add("Microsoft");