Nested Context menus on a radGrid

4 posts, 2 answers
  1. Tim
    Tim avatar
    15 posts
    Member since:
    Jul 2010

    Posted 18 Jan 2011 Link to this post

    I've got a basic context menu working on a RadGrid, but I want to include a 3rd context menu (with the arrow character >) that nestes and has a bunch of other menu items on its own menu panel. Would that need to be a combo box item?

    What I have working so far is this (pretty basic context menu):

    Dim contextMenu_Active As New RadContextMenu
      
    Dim menuItem1 = New RadMenuItem("Stop")
    menuItem1.ForeColor = Color.Red
    AddHandler menuItem1.Click, AddressOf menuItem1_Click
    Dim menuItem2 As New RadMenuItem("Remove")
    AddHandler menuItem2.Click, AddressOf menuItem2_Click
    contextMenu_Active.Items.Add(menuItem1)
    contextMenu_Active.Items.Add(menuItem2)
      
    Private Sub RadGridView_Active_ContextMenuOpening(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.ContextMenuOpeningEventArgs) Handles RadGridView_Active.ContextMenuOpening
            If TypeOf Me.RadGridView_Active.CurrentRow Is GridViewDataRowInfo Then
                e.ContextMenu = contextMenu_Active.DropDown
            End If
        End Sub
      
    Private Sub menuItem1_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim index As Integer = Me.RadGridView_Active.Rows.IndexOf(TryCast(Me.RadGridView_Active.CurrentRow, GridViewDataRowInfo))
            If index >= 0 Then
                Dim strGUID = Me.RadGridView_Active.Rows(index).Cells(0).Value
                Try
                    ccJob.JobStop(strGUID)
                Catch ex As Exception
      
                End Try
            End If
        End Sub
        Private Sub menuItem2_Click(ByVal sender As Object, ByVal e As EventArgs)
            'TODO
        End Sub
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 18 Jan 2011 Link to this post

    Hello Tim.

    You can add as many nested menu items as you need. (see screenshot).
    For exmaple: 
        
    Private contextMenu_Active As New RadContextMenu

    Dim menuItem1 = New RadMenuItem("Stop")
    menuItem1.ForeColor = Color.Red
    AddHandler menuItem1.Click, AddressOf menuItem1_Click
    Dim menuItem2 As New RadMenuItem("Remove")
    AddHandler menuItem2.Click, AddressOf menuItem2_Click
    Dim menuItem3 As New RadMenuItem("3rd Menu")
    Dim menuItem3a As New RadMenuItem("3a Menu")
    Dim menuItem3b As New RadMenuItem("3b Menu")
    '// TODO: add handlers
    menuItem3.Items.Add(menuItem3a)
    menuItem3.Items.Add(menuItem3b)
    AddHandler menuItem2.Click, AddressOf menuItem2_Click
    contextMenu_Active.Items.Add(menuItem1)
    contextMenu_Active.Items.Add(menuItem2)
    contextMenu_Active.Items.Add(menuItem3)

    Hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Tim
    Tim avatar
    15 posts
    Member since:
    Jul 2010

    Posted 18 Jan 2011 Link to this post

    Thanks, that was easier than I thought.

    One last question - what's the best way to know when a context menu is closed not via clicking on one of the menu choices. I have some Timers that are running and when the context menus are up, I'm going to pause them until either a menu item is clicked, or the user clicks somewhere else which in that case the context goes away. It's that case that I need to restart the Timers once the context menu goes away without a menu click.

    -Tim
  5. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 18 Jan 2011 Link to this post

    Hi Tim.

    Unfortunatly, I don't think that's possible because of the order the events fire. You can capture when the context menu closes via
    AddHandler contextMenu_Active.DropDownClosed, AddressOf ContextMenu_DropDownClosed
      
        Private Sub ContextMenu_DropDownClosed(ByVal sender As Object, ByVal e As EventArgs)
            MessageBox.Show("Closed")
        End Sub

    But this fires after the menu click, so you won't know if the menu is closed because it is closed via a click or if it is closed because it has lost focus.
    If my previous reply helped, please remember to mark that one as answer and if you have further questions, please let me know
    Richard
Back to Top