Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug RC0 - databind to combobox
18 replies. Latest Post by mamadero2 on August 31, 2009.
(0)
olexiy
Member
11 points
22 Posts
09-29-2008 9:28 AM |
Silverlight 2 RC0 project with 2 controls:
1 <ComboBox x:Name="ddl" Width="100"></ComboBox> 2 <Button x:Name="btn" Width="100"></Button>
And a bit of code
1 Private Sub btn_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btn.Click 2 Try 3 Dim col As New List(Of String) 4 col.Add("One") 5 col.Add("Two") 6 col.Add("Three") 7 ddl.ItemsSource = Nothing 8 ddl.ItemsSource = col 9 ddl.SelectedItem = "Two" 10 Catch ex As Exception 11 12 End Try 13 End Sub
Click on a little arrow to open combo box (it will be empty). Now click the button - Silverlight will trow an unhandled exception.Or, click a button, open combo box (so it has items) and click the button again - same exception.
An unhandled exception ('Sys.InvalidOperationException: ManagedRuntimeError error #4004 in control 'Xaml1': System.ArgumentException: Value does not fall within the expected range. at MS.Internal.XcpImports.MethodEx(IntPnt ptr, String name, CValue[]
Line 9 is the line that causes exception, although debugger goes thru it OK and in Try Catch block around these 6 lines Catch never called nor Application_UnhandledException method gets called.
If you don't open drop down in combo box with mouse but change value with keyboard, exception is not getting thrown. Opening drop down prior to selecting an item is what causes the exception.
.
09-29-2008 11:29 AM |
I have tried to use Selectedndex property instead of SelectedItem in combo box but this dosn't help.
I have also tried no to bind data but insted add into .Items collection, the same result, the same exception.
Please help, how can I select an item in the combo box progamatically?
Stephane...
140 points
32 Posts
09-29-2008 12:25 PM |
I have the same problem. It seems to happen only with your list of strings. If I use a Linq query as my source for the combobox, I can use SelectedIndex without problems (I haven't tried SelectedItem, but I guess it should work too).
Tregarick
13 points
24 Posts
09-30-2008 5:45 AM |
I am getting the same issue as well. I have a combo thats outside of a datagrid and its contents and selected item gets changed based on the currently selected row in the data grid. So I set the combos item source and SelectedItem properties in the 'SelectionChanged' event of the datagrid. As I hop from one row to another the combo box adjusts accordingly which is great. However if I change the combo boxes value and then select another row I get the same issue mentioned above 'Value does not fall within the expected range' #4004. I have tried using SelectedItem and SelectedIndex I have also tried adding strings directly to the combo's 'Items' property and binding to a list of strings but nothing seems to work. I saw this posting though which I think is the same http://silverlight.net/forums/p/31071/98695.aspx and it seems as this is a known issue.
Jonathan...
All-Star
24979 points
2,434 Posts
10-01-2008 12:25 AM |
Hi Olexiy,
It is a known issue. Below is a workaround. Please do it like this.
private void Button_Click(object sender, RoutedEventArgs e) { List<string> myList = new List<string>(); myList.Add("aaaa"); myList.Add("bbbb"); myList.Add("cccc"); myList.Add("dddd"); myComboBox.ItemsSource = null; myComboBox.ItemsSource = myList; myComboBox.UpdateLayout(); myComboBox.SelectedItem = "bbbb"; }
Best regards,
Jonathan.
10-01-2008 10:59 AM |
Now it doesn't error out, but a drop down thing is sooo small I can't choose anything in it. Would you advise how to fix that?
yvesc
20 points
16 Posts
10-01-2008 11:44 AM |
The UpdateLayout() trick fixed my issue. Thanks.
sanjay10
14 points
10-01-2008 3:34 PM |
Thanks Jonathan, I spent last night 3 hours figuring out this issue, till I Googgled and found your reply.
This is a nasty bug, MSFT should fix in Final release
10-01-2008 11:13 PM |
olexiy:Now it doesn't error out, but a drop down thing is sooo small I can't choose anything in it. Would you advise how to fix that?
It is a known issue. Our development team will fix it in the future released version. Thanks.
Jonathan
jemiller
445 points
237 Posts
10-14-2008 11:53 AM |
Is anyone else still running into this? As far as I can tell it wasn't fixed for RTW. I have also ran into the issue where the drop down is very small. I think what it does is set the drop down size to fit whatever is originally in the list. Then, if the number of items changes, it doesn't resize it. i.e. say the list is empty or has one item to begin with and you click to drop it down, the drop down will be small. Then, if other items are added to the list and you click the drop down again, it is still small. Does anyone know if there is a way to specify the size of the drop down part of the list explicitly? Either that, or, to somehow refresh it so that the size fits the items correctly? I don't see what the big rush on RTW was. It seems to me that Microsoft simply ignored bugs like this and released it anyway. I don't know what the point of RC0 was.
sladapter
17445 points
3,173 Posts
10-14-2008 12:15 PM |
jemiller:Is anyone else still running into this? As far as I can tell it wasn't fixed for RTW. I have also ran into the issue where the drop down is very small. I think what it does is set the drop down size to fit whatever is originally in the list. Then, if the number of items changes, it doesn't resize it. i.e. say the list is empty or has one item to begin with and you click to drop it down, the drop down will be small. Then, if other items are added to the list and you click the drop down again, it is still small. Does anyone know if there is a way to specify the size of the drop down part of the list explicitly? Either that, or, to somehow refresh it so that the size fits the items correctly? I don't see what the big rush on RTW was. It seems to me that Microsoft simply ignored bugs like this and released it anyway. I don't know what the point of RC0 was.
Exactly what my thought is on this final release. I would rather wait than getting a final buggy product.
10-14-2008 2:36 PM |
You are right, this problem was not fixed in the final release. I am amazed as well ....
10-14-2008 2:39 PM |
Have you tried the UpdateLayout() suggested above to resize the dropdown?
10-14-2008 5:01 PM |
yvesc:Have you tried the UpdateLayout() suggested above to resize the dropdown?
I tried, didn't do anything.
10-14-2008 5:24 PM |
I tried it and it looks like it might have fixed a problem where I wasn't able to set the SelectedItem. However, it didn't do anything with regard to the size of the drop down list.
10-14-2008 5:26 PM |
Does anyone know when SP1 is coming out?
bleaknik
2 points
3 Posts
10-17-2008 4:54 PM |
We've tried this work around using Silverlight 2.0 RTW, and we're still getting this fatal error. Our control is inside of a popup. Are there any other known workarounds? Also, does anyone know when Microsoft will be fixing this? Thanks, Jamal
walter1976
6 Posts
12-20-2008 11:08 AM |
THANKS!
Now i can finish my work before the deadline.
mamadero2
42 points
28 Posts
08-31-2009 1:35 AM |
Seems to be fixed in v3. I removed this "Hack" from several places and it's working fine.