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

Nested Context menus on a radGrid

3 Answers 166 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 18 Jan 2011, 07:27 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 18 Jan 2011, 10:38 PM
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
0
Tim
Top achievements
Rank 1
answered on 18 Jan 2011, 11:05 PM
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
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 18 Jan 2011, 11:25 PM
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
Tags
ContextMenu
Asked by
Tim
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Tim
Top achievements
Rank 1
Share this question
or