This is a migrated thread and some comments may be shown as answers.

RadContentMenu Exception

7 Answers 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
xu qing
Top achievements
Rank 1
xu qing asked on 06 Apr 2010, 04:29 AM
Hi,
    I use the RadContentMenu Control to provide contentmenu in my application.I write my code follow the demo:
    http://demos.telerik.com/silverlight/#GridView/RowContextMenu
    
    When I run my code and click right mouse on GridView,the contentmenu is not the menu I defind,it's the default right menu of Silverlight.The content of menu is:"Silverlight(S)".
    
    Then I use the MouseRightButtonDown Event of GridView to display RadContentMenu by Code.Follow is my event hand code:
    
    private void GList_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
          //open radcontentmenu
            this.ConentMenu.IsOpen = true;
            //disable default contentmenu
            e.Handled = true;
        }
    
    Then I run my code and right mouse on GridView,the RadContentMenu displayed.After that,I write the Opened Event of RadContentMenu,Follow is my code:
    
    private void ConentMenu_Opened(object sender, RoutedEventArgs e)
        {
         RadContextMenu menu = (RadContextMenu) sender;
        
         //Get the selectRow
            GridViewRow selectRow = menu.GetClickedElement<GridViewRow>();

            if (selectRow != null)
            {
              //Set the selectRow as local select row
                selectRow.IsSelected = true;
            }
        }
    
    I run my code again,An Exception happend in the RadContentMenu Opend Event hand Code.The Expend is:Value is not within the expected range.
    
    Follow is the detail of this Exception:
    
    System.ArgumentException was unhandled by user code
   Message=Value is not within the expected range.
   StackTrace:
       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 Telerik.Windows.Controls.ApplicationHelper.TransformToScreenRoot(UIElement target)
       At Telerik.Windows.Controls.VisualTreeHelperExtensions.GetElementsInHostCoordinates[T](UIElement subtree, Point position)
       At Telerik.Windows.Controls.VisualTreeHelperExtensions.<>c__DisplayClass5`1.<GetElementsInScreenCoordinatesFromOpenedPopups>b__4(Popup p)
       At System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
       At System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
       At System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
       At Telerik.Windows.Controls.RadContextMenu.GetClickedElement[T]()
       At SSMP.SysManager.UserManager.ConentMenu_Opened(Object sender, RoutedEventArgs e)
       At Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
       At Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
       At Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
       At Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
       At Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
       At Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
       At Telerik.Windows.Controls.RadContextMenu.OnOpened(RadRoutedEventArgs e)
       At Telerik.Windows.Controls.RadContextMenu.OnPopupOpened(Object source, EventArgs e)
       At MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       At MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
   InnerException: 
  
   I checked my code with demo,I can't find why my code get this exception.I use the VS2010 beta2 AND Silverlight4 Beta.Telerik 2010 Q1 Silverlight Control.
  
   Could somebody help me fixed my code.Or write a simple demo for me?
  
   Thanks very much.

7 Answers, 1 is accepted

Sort by
0
xu qing
Top achievements
Rank 1
answered on 09 Apr 2010, 04:14 AM
Did somebody get the same exception?No body could help me hand this?
0
Miroslav Nedyalkov
Telerik team
answered on 09 Apr 2010, 10:16 AM
Hello,

 Could you please provide us with a sample project that reproduce the problem? This way we will be able to better assist you fixing the problem.

Kind regards,
Miroslav Nedyalkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
xu qing
Top achievements
Rank 1
answered on 10 Apr 2010, 08:45 AM
Hi,
    I can't upload my demo code,Is there any way to upload it?
    Thanks.
  
0
xu qing
Top achievements
Rank 1
answered on 14 Apr 2010, 06:55 AM
Hi,
    Can you give me a way to upload my demo code?The Forums Attach files only upload image file,can't upload zip file.
0
Tobania
Top achievements
Rank 1
answered on 03 Jun 2010, 09:28 AM
Hello,

I experience the same "Value is not within the expected range" exception in the ContextMenu_Opened method. Specifically, it happens when I right-click immediately after left-clicking on a gridview row. Did you already find a solution for this problem? 

Here is my code. The exception occurs at the line "GridViewRow row = menu.GetClickedElement<GridViewRow>();"
private void ContextMenu_Opened(object sender, RoutedEventArgs e)  
        {  
            RadContextMenu menu = (RadContextMenu)sender;  
            GridViewRow row = menu.GetClickedElement<GridViewRow>();  
 
            if (row != null)  
            {  
                /*
                 * If the row clicked upon was not selected, all other selected items
                 * will be reset, and the context menu aplies only to this single row.
                 * If the row wás selected before the context menu is opened, 
                 * the context menu will aply to all the selected items.
                 */ 
                if (!row.IsSelected)  
                {  
                    functionList.SelectedItems.Clear();  
                }  
                row.IsSelected = row.IsCurrent = true;  
                GridViewCell cell = menu.GetClickedElement<GridViewCell>();  
                if (cell != null)  
                {  
                    cell.IsCurrent = true;  
                }  
            }  
            else 
            {  
                menu.IsOpen = false;  
            }  
        } 

Thanks
Sodi
0
xu qing
Top achievements
Rank 1
answered on 03 Jun 2010, 10:11 AM
Hi,
I got this exception because I use a radwindow control in the login xaml file "login.xaml",and when I goto main.xaml,the radwindow didn't closed.when I close this window before goto main.xaml,the exception don't happend.
By the way,If you select the radsilverlight project when you create your project.the mouserightbutton event will be handled automatic.
0
Hristo
Telerik team
answered on 08 Jun 2010, 07:12 AM
Hi xu qing,

Let us know if you need further assistance.

Regards,
Hristo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
xu qing
Top achievements
Rank 1
Answers by
xu qing
Top achievements
Rank 1
Miroslav Nedyalkov
Telerik team
Tobania
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or