Skip to main content

Microsoft Silverlight

Answered Question unhandle exception "undhandled error in silverlight 2 application" code:4004 .. value out of rangeRSS Feed

(0)

silverstarter
silverst...

Member

Member

216 points

146 Posts

unhandle exception "undhandled error in silverlight 2 application" code:4004 .. value out of range

(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)

if (_start > 0 && _start <= _end)

{

comboboxfiller =
new int[_end - _start + 1];for (int i = 0; i <= _end - _start; i++)

{

comboboxfillerIdea = 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
StefanWick

Contributor

Contributor

2864 points

438 Posts

Microsoft

Re: unhandle exception "undhandled error in silverlight 2 application" code:4004 .. value out of range

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 

 

Microsoft Silverlight | http://blogs.msdn.com/swick/

silverstarter
silverst...

Member

Member

216 points

146 Posts

Answered Question

Re: unhandle exception "undhandled error in silverlight 2 application" code:4004 .. value out of range

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 :)

greetings

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

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities