Skip to main content

Microsoft Silverlight

Answered Question Silverlight Combo SelectionItem issueRSS Feed

(0)

mahendranvs
mahendranvs

Member

Member

8 points

6 Posts

Silverlight Combo SelectionItem issue

 

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   
 

Cheers,
Mahendran Shanmugham

varshavmane
varshavmane

Contributor

Contributor

6739 points

1,583 Posts

Re: Silverlight Combo SelectionItem issue

Check this post :

http://silverlight.net/forums/t/98287.aspx

Hope it helps you Smile

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

mahendranvs
mahendranvs

Member

Member

8 points

6 Posts

Re: Silverlight Combo SelectionItem issue

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.

Cheers,
Mahendran Shanmugham

varshavmane
varshavmane

Contributor

Contributor

6739 points

1,583 Posts

Re: Re: Silverlight Combo SelectionItem issue

Can you please post your code for selected item, what exactly you are doing?

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

Mog Liang - MSFT
Mog Lian...

All-Star

All-Star

15962 points

1,552 Posts

Answered Question

Re: Silverlight Combo SelectionItem issue

please make sure combobox's itemsource has been set when changing selecteditem/index.

try execute selection code in Dispatcher.BeginInvoke();

Mog Liang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities