Shaitan00 Posted March 26, 2005 Posted March 26, 2005 --Using [VS C#.NET]-- This is really odd, I have a Method that is made to Refresh my GUI (clear my Combobox, re-populated them, and set the indexes back to -1). How I have noticed that after using the combobox.Items.Clear() my .SelectedIndex = -1 doesn't work. Given a Combobox [cb] cb.Items.Clear(); foreach (DataRow dr in ds.Tables[0].Rows) { cb.Items.Add(diInfo); } cb.SelectedIndex = -1; The 1st time my code runs it is perfect, however whenever I refresh (run this section again) the .Clear and .Add work (I have tested that it refreshes) however the cb.SelectedIndex = -1 does not work anymore, the last select item is still in he combobox. Any clues/ideas? Thanks, Quote
*Experts* DiverDan Posted March 26, 2005 *Experts* Posted March 26, 2005 That is weird, after clearing the items in the combobox setting the selected index to - 1 should do nothing. Try removing the cb.SelectedIndex = -1; Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
HJB417 Posted March 26, 2005 Posted March 26, 2005 1) After invoking cb.Items.Clear(), make sure cb.Items.Count is 0. 2) What's diInfo? You iterate through the rows, but add the same object reference to the ComboBox. 3) Setting SelectedIndex to -1 just deselects. It doesn't remove any items. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.