Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug SelectedIndex causes exception on ComboBox - Silverlight 2
12 replies. Latest Post by tyrel on July 17, 2009.
(0)
tyrel
Member
16 points
25 Posts
05-28-2009 12:39 PM |
Simple really, create two combo boxes. Make the first one populate data in the second setting the ItemsSource to a list, then select the first item in the list using SelectedIndex = 0. First time this works. Change the selection on the second combo box, then change the selection on the first again and hey presto, you get an exception.
http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=SilverlightComboBox&DownloadId=5948
I should add that I assume it's a bug, not really anything unusual about what I am trying to do there. Does anyone know if there are any workarounds for this problem? And has it been fixed in SL 3? Thanks.
RogerGu
Participant
887 points
260 Posts
05-29-2009 12:19 AM |
I tried a few times while debugging, pretty sure I followed the instructions. I did not get an exception thrown.
Twitter
05-29-2009 8:55 AM |
Weird. Using the sample I provided? I will get someone else here to try it. I have had weird problems before with Silverlight where things don't work, reboot and hey presto, they work again. I got the error in an application I am working on, then created the sample to see if it's related to some other code in there or not. Literally select item in combo box 1, change selection in combo box 2, change selection in combo box 1 and exception. I have no way of getting around it at this point. I guess I will try a reboot and see if that works, seems like the typical customer support response though. "Sir, have you rebooted your computer yet?". :-)
05-29-2009 9:18 AM |
I just had a co-worker try the sample on their computer and he got the exception to occur as well. The error I get seems to be the generic Silverlight error where it goes to JScript onSilverlightError function. I hope I don't have to create a custom control drop down box to get around this, that would seem like a whole lot of work to do to get around a problem with a build in control. Anyone else with some ideas?
05-29-2009 9:56 AM |
Yes, with the sample provided. Sorry I am no help. I'll try a different pc later today if I get the chance.
05-29-2009 10:03 AM |
Thanks mate. This is driving me nuts. :-) It's not like I am trying to do something totaly weird here. I do wonder if it has something to do with the version of Silverlight, you don't have 3 installed do you?
shailesh...
99 points
43 Posts
06-09-2009 5:15 AM |
Hi,
Similar kind of problem i'm facing. I'm having two comboboxes. on select of first other combobox get populated. so on change of first combobox second one get re-populated with new values. after populating i'm setting its SelectedIndex to 0 so that it points to 1st item in dropdown.
here every thing works fine. But when i open 2nd dropdown after populate; and changing its value or without changing its value, if i select other value in 1st drop down then it populates 2nd dropdown again. This time if i set SelectedIndex property of 2nd dropdown throws some exception. I'm not getting debug point in app.xaml.cs's Unhandleexception event but application_end event get fired and it closes application. On UI silverlight part disappears.
code for binding :
ddlClasses.ItemsSource = null; ddlClasses.ItemsSource = classList; ddlClasses.DisplayMemberPath = "Name"; ddlClasses.IsEnabled = true; ddlClasses.SelectedIndex = 0;
if SelectedIndex is not set then it works fine.
does any one have found any solution for this?
StefanWick
Contributor
2864 points
438 Posts
06-10-2009 1:11 AM |
We have addressed this for Silverlight 3. Can you try the Silverlight 3 Beta to verify this no longer repros?
In Silverlight 2 you should be able to work around this by calling UpdateLayout() before setting the SelectedIndex.
Let me know if this doesn't help.
Thanks, Stefan Wick
06-10-2009 2:59 AM |
Thanks,
Using UpdateLayout before SelectedIndex set works.
06-11-2009 3:47 PM |
Thanks Stefan! I will add the code. We cannot use 3 at the moment. Don't think it will be released by the time we have to release.
rajkra
33 points
36 Posts
07-17-2009 5:28 AM |
How to do UpdateLayout() because it returns false
07-17-2009 8:27 AM |
Not sure exactly what the problem is you are facing, but all I did was call UpdateLayout before setting the selected index, like this:
UserStatusComboBox.ItemsSource = userStatuses; UserStatusComboBox.UpdateLayout(); UserStatusComboBox.SelectedIndex = 0;
07-17-2009 8:32 AM |
Sorry for the long delay Stefan, but we upgraded to Silverlight 3 now that it has been released and I tried the sample again. It works! So looks like the problem has been fixed in version 3.
Thanks.
PS. Now can we get printing from SL? :-)