Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Silverlight Combo SelectionItem issue
4 replies. Latest Post by Mog Liang - MSFT on June 23, 2009.
(0)
mahendranvs
Member
8 points
6 Posts
06-18-2009 8:53 AM |
There Seems to be an issue in Silverlight Combobox 2.0.
Exception:
Value does not fall within the expected range.
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
at MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement visual)
at System.Windows.UIElement.TransformToVisual(UIElement visual)
at System.Windows.Controls.Primitives.Selector.IsOnCurrentPage(Int32 index, Rect& itemsHostRect, Rect& listBoxItemRect)
at System.Windows.Controls.Primitives.Selector.ScrollIntoView(Int32 index)
at System.Windows.Controls.Primitives.Selector.SetFocusedItem(Int32 index, Boolean scrollIntoView)
at System.Windows.Controls.ComboBox.PrepareContainerForItemOverride(DependencyObject element, Object item)
at iQor.Pars.SilverLight.Controls.IqorComboBox.PrepareContainerForItemOverride(DependencyObject element, Object item)
Combobox in Silverlight seems to have some issue while setting the SelectedItem or index. I tried with updatedLayout, but still it throw exeception. So I have derived the control and override the PrepareContainerForItemOverride method and call the base method with try catch. This solved the issue and Selected item seems to be working fine. This may not be bestway. But this is working fine for me.
1 public class MyCombo : ComboBox 2 { 3 protected override void PrepareContainerForItemOverride(DependencyObject element, object item) 4 { 5 try 6 { 7 base.PrepareContainerForItemOverride(element, item); 8 } 9 catch 10 { } 11 } 12 } 13
varshavmane
Contributor
6739 points
1,583 Posts
06-18-2009 8:59 AM |
Check this post :
http://silverlight.net/forums/t/98287.aspx
Hope it helps you
06-18-2009 9:54 AM |
Thanks for your reply.
I have already implemented the code using the selected Item or Selectedindex which works fine when the control is loaded. But after reloading the same combobox during some evernts,and at the time when i try to set the selected item, this above exception is thrown.
06-18-2009 10:42 AM |
Can you please post your code for selected item, what exactly you are doing?
Mog Lian...
All-Star
15962 points
1,552 Posts
06-23-2009 10:46 PM |
please make sure combobox's itemsource has been set when changing selecteditem/index.
try execute selection code in Dispatcher.BeginInvoke();