Nel

Nel

  • NA
  • 716
  • 1.1m

How to insert new item in a combobox

Feb 28 2012 7:17 AM
Hello,
I fill the combobox on the following way

 OleDbDataAdapter datAd = new OleDbDataAdapter();
                datAd.SelectCommand = new OleDbCommand();
                datAd.SelectCommand.Connection = conn;
                datAd.SelectCommand.CommandText = "SELECT NOVI.GBR FROM NOVI WHERE NOVI.GBR NOT IN (SELECT  Avtobusi.Garbr FROM Avtobusi) UNION (select Avtobusi.Garbr from Avtobusi,NOVI where Avtobusi.Sloboden=true)";
              
                datAd.SelectCommand.ExecuteNonQuery();

                _dataset.Clear();
                datAd.Fill(_dataset, "NOVI");

                comboBox1.DataSource = _dataset.Tables["NOVI"];
                comboBox1.DisplayMember = "GBR";


and I want to insert an empty field in the beggining of the combobox.
I tried with this:
comboBox1.Items.Add(" ");
            comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
but it can't be done like this. The combobox remain the same, without the empty item at the beginning.

Can anybody help me please?
Thanks

Answers (6)