Skip to main content
Home Forums Silverlight Programming Programming with .NET - General unhandle exception "undhandled error in silverlight 2 application" code:4004 .. value out of range
2 replies. Latest Post by silverstarter on October 7, 2008.
(0)
silverst...
Member
216 points
146 Posts
10-06-2008 11:42 AM |
(hope that was the right translation)
hi im using comboboxes and receiving this error when i switch a value in a combobox and generate it new(see code below), if i didnt switch a value (using the default one) and generate it new, it works without that error
a part of the sourcecode: (_start and _end have values between 1 and 31)
{
comboboxfiller = i + _start;
}
ComboBoxStart.ItemsSource = comboboxfiller;
ComboBoxStart.SelectedItem = _start;
ComboBoxEnd.ItemsSource = comboboxfiller;
ComboBoxEnd.SelectedItem = _end;
do i have to reset something ?
or whats my mistake?
greetings
silverstarter
StefanWick
Contributor
2864 points
438 Posts
10-07-2008 12:34 AM |
Hi silverstarter,
this is a problem in the platform that has an easy workaround in app code. What's happening here is that you mark an item as selected that has not been laid out yet. By setting the ItemsSource you are creating implicitely a new collection of combobox items. Those have not received a Layout pass yet by the time you set the SelectedItem property.
To prevent the exception, wait until Layout has happened, or just force Layout to happen from your code:
ComboBoxStart.ItemsSource = comboboxfiller; ComboBoxEnd.ItemsSource = comboboxfiller; UpdateLayout(); ComboBoxStart.SelectedItem = _start; ComboBoxEnd.SelectedItem = _end;
Thanks, Stefan Wick
10-07-2008 2:13 AM |
very nice! :)
thats the right start into a working day ;)
reporting a problem at the evening and getting the answer untill the next day starts
thank u for letting my day start that way :)
Silverstarter
edit: weird.. i cant set your post as answer... i can click it but nothing happenes...
and since this morning i get, ish each 2nd time a page of this forum is loaded, a errormessage about 'stepchange' is undefined