المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Odd behaviour when selecting item in a Combobox [Fixed it, my fault]



C# Programming
10-03-2009, 04:50 AM
I have a List I use this list to populate a combo box so that the user can select an item from the list, and I can easily grab which one they selected:


onSelectedIndexChanged(...)
{
this.currentItem = this.comboBox.SelectedItem as MyClass;
}


The strange thing is, when you first select an item from the list, the box doesn't display any text. If you select the same item again, it does.
The box will only display the correct text if you select the same item twice in a row, and everything works as normal when I don't set this.currentItem

Upon further testing it seems to happen when I access properties on the instance of MyClass right after selecting it. If I comment out a bunch of code the combo box works fine, although it's only reading a few values nothing is actually being changed, not that I see how it could make any difference.


Does anybody have any idea what's going on?

EDIT: I know what it was, purely my fault. When an item was selected a numeric up down control was set with a value from that item, this triggered the ValueChanged event, which reset the value back to the item, and triggered Sort on my list, which clears out and refills the combo box with the items in the new order. Bit of a pain in the arse really, I must pay more attention in future http://www.barakasoft.com/script/Forums/Images/smiley_doh.gif

My current favourite word is: Delicious!
-SK Genius

Game Programming articles start -here (http://www.codeproject.com/KB/game/skgameone.aspx)[^ (http://www.codeproject.com/KB/game/skgameone.aspx)]-


modified on Friday, October 2, 2009 10:15 AM