C# – How to set combobox default value

ccomboboxwinforms

In windows form, It has a ComboBox, Which have data binded by the DataSource.

When going to set the text property for a ComboBox.

Selected ComboBox -> Property -> Text : "–Select–".

Design page shows the given text. But when run the application the given text disappeard and the initial index value of a comboBox item appeared, Which is from the DataSource.

So i gave the ComboBox text in the Form load. I mean in the Constructor

public myform()
{
     InitializeComponent();
     ComboBox.Text="--Select--";
}

link revised and more. But ..

Setting default item in combo box

https://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.text(v=vs.110).aspx

Searched lot of question in SO depends to ComboBox. But those never solve my case

Edited

enter image description here

In that combobox, Click the right top corner , From that i choosed data for my combobox by using Datasouce. I didn't write any code for add items into combobox.

Best Answer

You can do something like this:

    public myform()
    {
         InitializeComponent(); // this will be called in ComboBox ComboBox = new System.Windows.Forms.ComboBox();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'myDataSet.someTable' table. You can move, or remove it, as needed.
        this.myTableAdapter.Fill(this.myDataSet.someTable);
        comboBox1.SelectedItem = null;
        comboBox1.SelectedText = "--select--";           
    }