default value in combobox
-
Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.
-
Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.
-
Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.
Use combobox SelectedIndex to select the default value in the combobox:cool:
-
Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.
When you're application loads, or when the combobox is filled, use this :
comboBox.SelectedIndex = 0; // ( or 1,2,3 .. depending on the item you'd like to show first )
-
Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.
The two answers above me are correct in different cases. If the DropDownStyle is DropDown (i.e. drop/edit), set the Text property to have an initial value. If it is DropDownList, set SelectedIndex (or SelectedItem). You should do this after InitialiseComponent is called; I typically do it lower down in the form class constructor. Alternatively, if you data bind the combos, they will initialise to the initial value of the property to which they are bound.
-
Hi all, In my c# application i.e., windows application i am using a combobox and in its collection properties i have added some data. When ever i run my application in combobox it doesn't show any default value,its shown empty until it is selected. How can i shown default value in combobox in windows application ? Thanks in advance.
this code may help you.. ;)
private void loadComboBox()
{
if (this.cmb.DataSource == null)
{
this.cmb.Items.Add("Please Wait");
this.cmb.Text = "Please Wait";
this.cmb.Refresh();
}DataTable tbl = comboData() as DataTable; tbl.Rows.Add(0, ""); cmb.DataSource = tbl; cmb.DisplayMember = "Name"; cmb.ValueMember = "Id"; cmb.SelectedValue = 0; }
-ambarish-