Home > DeveloperSection > Blogs > Combobox at runtime in c# wpf.

Combobox at runtime in c# wpf.


WPF WPF 
Ratings:
0 Comment(s)
 5538  View(s)
Rate this:


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">

       

</Grid>

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;

            cmb.Items.Add("Apple");

            cmb.Items.Add("Mango");

            cmb.Items.Add("Banana");

            cmb.Items.Add("Graps");

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

Finally execute your program to test your code.


Don't want to miss updates? Please click the below button!

Follow MindStick