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
Jignesh TrivediPosted Feb 29, 2012, 3:10 AM
now you change you query.
SELECT cast(NOVI.GBR FROM NOVI WHERE NOVI.GBR NOT IN (SELECT Avtobusi.Garbr FROM Avtobusi)
UNION
(select cast(Avtobusi.Garbr from Avtobusi,NOVI where Avtobusi.Sloboden=true)
Cast your interger value to string and try...
DataTable dt = _dataset.Tables["NOVI"];
DataRow dradd = dt.NewRow();
dradd["GBR"] = " "; // a single space
dt.Rows.InsertAt(dradd, 0); // place at top
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "GBR";
hope this help.
NelPosted Feb 29, 2012, 5:52 AM
NelPosted Feb 29, 2012, 2:24 AM
VulpesPosted Feb 28, 2012, 10:40 AM
NelPosted Feb 28, 2012, 8:41 AM
Jignesh TrivediPosted Feb 28, 2012, 7:46 AM
We cannot add new item in Item source.
but yes you can add your new row in datasouse i.e. in your data table.
DataTable dt = _dataset.Tables["NOVI"];
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "GBR";
DataRow dradd = dt.NewRow();
dt.Rows.Add(dradd);
hope this help.