Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

am binding combobox with datatable , and now i want to insert "select " in starting in combobox
here is my code: select is coming at last ,how to do ...

C#
<pre lang="c#">String query = "select machine_id from device";
                MySqlCommand command = new MySqlCommand(query,con);
                con.Open();
                MySqlDataAdapter da = new MySqlDataAdapter(query, con);
                DataTable dt = new DataTable();
                 da.Fill(dt);
                comboBox1.DataSource =dt;
                //comboBox1.Text = "select";
                comboBox1.DisplayMember = "machine_id";
                comboBox1.ValueMember = "machine_id";

                DataRow dr = dt.NewRow();
                dr["machine_id"] = -1;// Some ID
                dr["machine_id"] = "Select";
                dt.Rows.Add(dr);
                comboBox1.SelectedIndex = -1;
Posted

1 solution

Hello ,
try this one

---query to fetch data and load in DataTable
----
<br />
   da.Fill(dt);<br />
   DataRow dr=dt.NewRow();<br />
   dr["machine_id"]="Select";<br />
   dt.Rows.Insert(dr,0);<br />
<br />
   comboBox1.DataSource =dt;<br />
   comboBox1.DisplayMember = "machine_id";<br />
   comboBox1.ValueMember ="machine_id";<br />
   combobox1.SelectedIndex=0;<br />
<br />


thanks
 
Share this answer
 
Comments
Member 10263519 27-Feb-14 8:27am    
insert() method is not supporting , am getting error.It's winform application,
Member 10263519 27-Feb-14 8:30am    
instead of Insert(), i tried dt.Rows.InsertAt(dr,0);

now it's working

thanq so much
Animesh Datta 27-Feb-14 8:35am    
if your problem has solved then accept the answer .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900