Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i having a combo box in c# it is filled value from database sql server 2008,

i have ADD button,combo box and a list box ,My combo box in c# , is filled value from database sql server 2008,
When i select any item from combo box and press add button item can move from combo box to list box but it can not remove from combo box


shows error...Value does not fall within the expected range

code----

form load//
C#
fillOffence(combobox1);//It fills the offence names

Add Button ////

string query = select [O_ID],[O_Desc] from tblOffence where O_Name'" +combobox1.Text.ToString() +"';
           DataTable dt = DataManager.GetDataText(query);
           foreach (DataRow dataRow in dt.Rows)
           {
               lstDesc.Items.Add(dt.Rows[0][1]);
               Global.Offence_id = Global.Offence_id + dt.Rows[0][1].ToString() + ;
error-->>        combobox1.Items.Remove(combobox1.SelectedItem);

               

           }
Posted
Updated 19-Oct-14 21:38pm
v2
Comments
Abhijit Ghosh (Subho) 20-Oct-14 3:48am    
This is odd. Debug and check what value combobox1.SelectedItem holds currently.
Richard MacCutchan 20-Oct-14 4:50am    
What is the error?
shekhar258395 20-Oct-14 5:10am    
Error Value does not fall within the expected range
Richard MacCutchan 20-Oct-14 5:14am    
What is the value, what is the range it is supposed to fall within? Try and use your debugger to collect some more detailed, and useful, information.
[no name] 20-Oct-14 6:46am    
The error often appears when selected item doesn't a member of collection which was set to ItemsSource property of ComboBox.
How are you binding the combo ?

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