Combobox at runtime in c# wpf.

In this blog I am going to tell you that how to add elements in combo box at runtime using c# code.

Follow these steps to implement this task.

Write down following xaml code :

<Grid Loaded="Grid_Loaded" x:Name="grid1">



At the load events of grid control write down following code to add combo box.

ComboBox cmb = new ComboBox();  //Create an object of combo box.

            cmb.Width = 200;  //set width of combo box.

            cmb.Height = 30;  //set height of combo box.

            cmb.Items.Add("---Select Fruits---");  //add items in combo box.

            cmb.SelectedIndex = 0;





grid1.Children.Add(cmb);  //Add combo box in grid control.

Finally execute your program to test your code.

Leave Comment