Community
Showing results for 
Search instead for 
Do you mean 
Reply

Add item to Context Menu

Tuned Listener
Posts: 10
Country: Brazil

Add item to Context Menu

Hello,

 

I need to add a new custom item to the context menu that pops up when you right click on the Calendar View.

 

Does anyone have a suggestion on how to do that ? I could not find any in the forum nor in the SDK.

 

Thanks.

Tuned Listener
Posts: 10
Country: Brazil

Re: Add item to Context Menu

OK, I finaly figured out how to do that, thanks to the following tip from Jin Durkin:

 

http://community.act.com/t5/Sage-ACT-Developer-s-Forum/Where-can-I-find-the-context-menu-in-the-regi...

 

For reference here is the code:

 

Private Sub ActApp_CurrentViewChanged(ByVal Sender As Object, ByVal e As System.EventArgs)

 

        If ActApp.CurrentViewName = "Act.UI.ICalendarView" Then

            ' OK, this is the Calendar View in ACT!

            Try

                ' Find the control to add the context menu to

                Dim MainContextMenu As Control

                Dim view As Form = DirectCast(ActApp.CurrentView, Form)

                txt = ""

                MainContextMenu = FindControl("ultraDay", view.Controls)

 

                If Not MainContextMenu Is Nothing Then

                    Dim j As Integer

                    Dim caption As String = "     &Ir para o processo"

 

                    ' Check if we have already added the menu item

                    For j = 0 To MainContextMenu.ContextMenu.MenuItems.Count - 1

                        If MainContextMenu.ContextMenu.MenuItems(j).Text = caption Then Exit Sub

                    Next

 

                    ' Create the menu item

                    Dim NewMenuItem As MenuItem

                    NewMenuItem = New MenuItem(caption, New EventHandler(AddressOf OnMenuItemClick), Nothing)

 

                    'Find the 'go to contact' menu index (the new item will be inserted close to it)

                    For j = 0 To MainContextMenu.ContextMenu.MenuItems.Count - 1

                        If MainContextMenu.ContextMenu.MenuItems(j).Text = "&Go To Contact" Then

                            Exit For

                        End If

                    Next

 

                    ' Add the Top Menu

                    Dim n As Integer = MainContextMenu.ContextMenu.MenuItems.Add(j, NewMenuItem)

 

                    ' Add the Popup Handler

                    AddHandler MainContextMenu.ContextMenu.Popup, AddressOf Main_ContextMenu_Popup

                End If

            Catch ex As Exception

                'Log your error here

            End Try

        End If

    End Sub

 

 

    Function FindControl(ByVal Nome As String, ByVal Ctrl As Object) As Control

        Try

            For Each CTL As Control In Ctrl

                If CTL.Name.ToLower = Nome.ToLower Then

                    Return CTL

                End If

                Dim c As Control = FindControl(Nome, CTL.Controls)

                If Not IsNothing(c) Then Return c

            Next

        Catch ex As Exception

            Dim s As String

            s = ex.Message

        End Try

        Return Nothing

    End Function

 

   

Sub OnMenuItemClick(ByVal sender As Object, ByVal e As EventArgs)

        MsgBox("Context Menu Clicked...")

End Sub

 

Sub Main_ContextMenu_Popup(ByVal sender As Object, ByVal e As EventArgs)

  'Fires before context menu opening…

 End Sub

 

 

Do not forgeto to add the event handler for ActApp_CurrentViewChanged