blog

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

Combobox at runtime in c# wpf.

Anonymous User8298 28-Apr-2011

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.

Updated 18-Sep-2014
I am a content writter !

Leave Comment

Comments

Liked By