I am working on combo box, i am refresh the combo box values , first i am deleting all values and then re populating it. But it is not working. The code duplicates the values in combo box which is creating problem. Here is my Code.
for (int i = 0; i < updateCombo.Items.Count; i++)
updateCombo.Items.RemoveAt(i);
//----------- Now Adding New Values --------
updateCombo.Items.Add("Select an option . . .");
SqlCommand command = new SqlCommand(Queries.qry9, connection);
SqlDataReader reader = command.ExecuteReader();
Kindly please help me in fixing this problem.
Not sure why this would happen- but if Items.Count comes back as 0 then your loop won’t remove any of the existing contents from the items list and you’ll get duplicates.
have you tried just clearing all the contents of the list regardless using:
It saves you having to iterate through them all, removing them one by one anyway.