Issues with Dynamic submenu in context menu.

2 posts, 0 answers
  1. Ganesh
    Ganesh avatar
    4 posts
    Member since:
    Jul 2006

    Posted 13 Apr 2012 Link to this post

    We have a RadContextMenu named “ContextMenu” and “miOpen” is RadMenuItem of the context menu, its created in XAML as shown below.

    XAML CODE is: -

    <telerikNavigation:RadContextMenu x:Name="ContextMenu" IsOpen="False" Visibility="Collapsed">
    <telerikNavigation:RadMenuItem Header="OpenForm" Name="miOpen" Click="miOpen_Click">
    <Image Source="../Images/Open.png" Stretch="None"/>

    We want to Create SubMenus in “miOpen” at run time dynamically, these submenus items can change at every right click, here is the cs code for dynamic menu creation.
    We are using RemoveAt() method as we have to change the SubMenus at every right click (but not in above cs code). 

    On First Right Click...above code working good but its giving error “Value does not fall within the expected range” after first rigth click.

    Here is CS CODE: -
                    Telerik.Windows.Controls.RadMenuItem objRadMenuMainMenu =
                    for(int k = 0; k<objRadMenuMainMenu.Items.Count;k++)
      for (int i = 0; i < 5; i++)
                        Telerik.Windows.Controls.RadMenuItem objConnPart = new           
                        objConnPart.Header = i.ToString() + "Header";
                        objConnPart.Name = i.ToString() + "Name";
                        objConnPart.Tag = i.ToString() + "Name";
                        objRadMenuMainMenu.Items.Insert(i, objConnPart);                   
                  ContextMenu.Visibility = Visibility.Visible;
     catch (Exception ex)

    Here are the exception: -

    Base exception:

    Value does not fall within the expected range. at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, Boolean b) at System.Windows.DependencyObject.SetValue(DependencyProperty property, Boolean b) at System.Windows.Controls.Primitives.Popup.set_IsOpen(Boolean value) at Telerik.Windows.Controls.PopupManager.Open(Popup popup, Boolean attachToVisualRoot) at Telerik.Windows.Controls.PopupManager.OpenPopup(Popup popup, Boolean attachToVisualRoot) at Telerik.Windows.Controls.PopupManager.Open(Popup popup, PopupType type, Boolean attachToVisualRoot) at Telerik.Windows.Controls.PopupWrapper.ShowPopup() at Telerik.Windows.Controls.RadContextMenu.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue) at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at Telerik.Windows.Controls.RadContextMenu.set_IsOpen(Boolean value) at Telerik.Windows.Controls.RadContextMenu.TriggerEventFired() at Telerik.Windows.Controls.RadContextMenu.OnEventTriggered(Object sender, EventArgs e) at Telerik.Windows.Controls.RadContextMenu.OnElementWithContextMenuMouseClick(Object sender, MouseButtonEventArgs 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, Int32 actualArgsTypeIndex, String eventName)

    Please check above code and give us solution.

    MCL Systems.



  2. Konstantina
    Konstantina avatar
    2332 posts

    Posted 17 Apr 2012 Link to this post


    You could find more information about how to add dynamically items to the ContextMenu in this help article:

    Hope this helps.

    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top