Strange ListBox databinding

When databinding IList to  listbox, the setter won’t be triggered when calling IList.Add(). I had to use a local variable, then set it back to view property to trigger the setter.

The listbox won’t automaticlly refresh/update the changes in IList, the stupid way of working around is set datasource to null, then set it to new value.

Looks like using CuccencyManager looks more professional? Here is MS’s instruction for CurrencyManager.

Advertisements

Watch out the data type when doing databind

We spent almost 3 hours today on trying to figure a weird problem about databinding combo box. The error just doesn’t make sense at all. What we wanted to do is very general and simple,  showing text in display area, but save key value back to object’s property.

We kept getting the selected index back to -1 when tabbing out from combo box control, debugged into combobox_selectIndexChanged method, tried to do a cast to int from comboBox.SelectedValue. The comipler didn’t allow us to do that, complained data should be less than infinity.

What? We then added a intermediate cast, first cast to int, then cast this int to short. The problem went away.

That why, short and int just don’t match automatically when databinding.

Another example of telling me that UI work is hard.