Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a ComboBox which is bind by Query(with Database) when new window call(that means constructor). Now I want to add "Select" at index 0.so how can i add ??
I used
ComboBox1.Text="--Select--"
but it is not working.
then i tried
if (cmbGroup.Items.Count > 0)
           {
               cmbGroup.Items.Insert(0, "Select Item");
               cmbGroup.SelectedIndex = 0;
           }

or
cmbGroup.Items.Insert(0, "Select Item");
cmbGroup.SelectedIndex = 0;

but it gives an exception that is- Operation is not valid while ItemSource is in use. Access and Modify elements with ItemsControl.ItemSource instead. so what can i do ??
Posted
Updated 11-Feb-15 23:32pm
v2

 
Share this answer
 
Comments
J{0}Y 12-Feb-15 5:33am    
i updated my question please check.
J{0}Y 12-Feb-15 6:46am    
suggest answer according linq to sql because i m using linq to sql
you should get the value from the Source only if you using the Databound method.

best thing you can do is, use union in sql for getting your desired value at top

like

SQL
select id, name from emp
union all
select 0, '--Select Any--'
order by id
 
Share this answer
 
Comments
J{0}Y 12-Feb-15 5:59am    
how to write this query in linq to sql ??

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