Community
Showing results for 
Search instead for 
Do you mean 
Reply

How to add a button to Opportunity toolbox?

Accepted Solution Solved
Tuned Listener
Posts: 38
Country: Poland
Accepted Solution

How to add a button to Opportunity toolbox?

What is wrong? Its does not work Smiley Sad

 

 

void Button_Click(object sender, EventArgs e)
{
    MessageBox.Show("Button_Click");
}

 

//.....

 

if (m_actApp.CurrentViewName == "Act.UI.IOpportunityDetailView")
{
                Act.UI.Core.CommandBar bar = m_actApp.CurrentView.GetCommandBarCollection()[0];
                Act.UI.Core.CommandBarButton but = new Act.UI.Core.CommandBarButton("Button Text", "Button tooltip", new EventHandler(Button_Click), "", "");
                but.DisplayStyle = Act.UI.Core.CommandBarControl.ItemDisplayStyle.TextOnly;
                bar.ControlCollection.Add(but, true);
 }


Accepted Solutions
Solution
Accepted by topic author bernardo
‎09-25-2015 03:20 AM
Employee
Posts: 1,163
Country: USA

Re: How to add a button to Opportunity toolbox?

Here's the code that I used to add a button to the Opportunity List/Detail Toolbar:

 

void actApp_ViewLoaded(object sender, ViewEventArgs e)
{
        if (ActApp.CurrentViewName == "Act.UI.IOpportunityDetailView" ||
ActApp.CurrentViewName == "Act.UI.IOpportunityView")
        {
            AddMenuIcon();
        }
}

The views aren't all loaded by the AfterLogon event, so instead I chose to add the icon during the ViewLoaded event.

 

private void AddMenuIcon()
{
        try
        {
            CommandBarButton NewButton;

            NewButton = new CommandBarButton("Test""Test"null"Test", img, img);
            NewButton.DisplayStyle = CommandBarControl.ItemDisplayStyle.ImageOnly;
            NewButton.Text = "TEST";
            ActApp.RegisterCommand("Test", CreateNote, RegisterType.Shell);

            try
            {
                for (int i = 0; i <= ActApp.Explorer.CommandBarCollection.Count - 1; i++)
                {
                    CommandBar cb = ActApp.Explorer.CommandBarCollection[i];
                    if (cb.Type == CommandBarType.Toolbar && !cb.CustomBar && cb.Name ==
"Opportunity Detail Toolbar"
 || cb.Name == "Opportunity List Toolbar")
                        {
                            if (!ActApp.Explorer.CommandBarCollection[i].ControlCollection.Contains(NewButton.Command))
                            {
                                ActApp.Explorer.CommandBarCollection[i].ControlCollection.Add(NewButton);
                            }
                        }
                    }
                }
                catch (Exception E)
                {
                     
                }
            }

            catch (Exception X)
            {
                 
            }
        }

CreateNote is a method I had from another project, it could really be any method that accepts a string as its only parameter. img is also not initialized within this code block, but it's simply a System.Drawing.Image object on my local machine.

 

Here's what it looks like:

 

Matthew Wood
Act! SDK Support
Community Moderator

View solution in original post


All Replies
Employee
Posts: 1,163
Country: USA

Re: How to add a button to Opportunity toolbox?

Hello bernardo,

 

In what way does it not work? Does it not display, or is the on click event not firing? If it's the former, then when are you adding the button (in other words, during which event are they being added).

Matthew Wood
Act! SDK Support
Community Moderator
Tuned Listener
Posts: 38
Country: Poland

Re: How to add a button to Opportunity toolbox?

Hello!

button does ot apperes on the toolbox (not visible) Smiley Sad

 

but code bellow shows "15" and "16":

 

MessageBox.Show(bar.ControlCollection.Count.ToString());
bar.ControlCollection.Add(but, true);
MessageBox.Show(bar.ControlCollection.Count.ToString());

 

best regards

Solution
Accepted by topic author bernardo
‎09-25-2015 03:20 AM
Employee
Posts: 1,163
Country: USA

Re: How to add a button to Opportunity toolbox?

Here's the code that I used to add a button to the Opportunity List/Detail Toolbar:

 

void actApp_ViewLoaded(object sender, ViewEventArgs e)
{
        if (ActApp.CurrentViewName == "Act.UI.IOpportunityDetailView" ||
ActApp.CurrentViewName == "Act.UI.IOpportunityView")
        {
            AddMenuIcon();
        }
}

The views aren't all loaded by the AfterLogon event, so instead I chose to add the icon during the ViewLoaded event.

 

private void AddMenuIcon()
{
        try
        {
            CommandBarButton NewButton;

            NewButton = new CommandBarButton("Test""Test"null"Test", img, img);
            NewButton.DisplayStyle = CommandBarControl.ItemDisplayStyle.ImageOnly;
            NewButton.Text = "TEST";
            ActApp.RegisterCommand("Test", CreateNote, RegisterType.Shell);

            try
            {
                for (int i = 0; i <= ActApp.Explorer.CommandBarCollection.Count - 1; i++)
                {
                    CommandBar cb = ActApp.Explorer.CommandBarCollection[i];
                    if (cb.Type == CommandBarType.Toolbar && !cb.CustomBar && cb.Name ==
"Opportunity Detail Toolbar"
 || cb.Name == "Opportunity List Toolbar")
                        {
                            if (!ActApp.Explorer.CommandBarCollection[i].ControlCollection.Contains(NewButton.Command))
                            {
                                ActApp.Explorer.CommandBarCollection[i].ControlCollection.Add(NewButton);
                            }
                        }
                    }
                }
                catch (Exception E)
                {
                     
                }
            }

            catch (Exception X)
            {
                 
            }
        }

CreateNote is a method I had from another project, it could really be any method that accepts a string as its only parameter. img is also not initialized within this code block, but it's simply a System.Drawing.Image object on my local machine.

 

Here's what it looks like:

 

Matthew Wood
Act! SDK Support
Community Moderator
Tuned Listener
Posts: 38
Country: Poland

Re: How to add a button to Opportunity toolbox?

Thank you very much, it works

 

best regards

B.

Tuned Listener
Posts: 17
Country: France

Re: How to add a button to Opportunity toolbox?

Hi,

 

This old code works for me, but how we do to remove a button?

 

thanks

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: How to add a button to Opportunity toolbox?

   Public Shared Sub RemoveToolBarItem(ByVal urn As String, ByVal ACTAPP As Act.UI.ActApplication)
        Try
            ACTAPP.RevokeCommand(urn)

            Dim RemoveToolBar As Act.UI.Core.CommandBarControl
            Dim tBar As Act.UI.Core.CommandBar
            For Each tBar In ACTAPP.Explorer.CommandBarCollection
                ' We only add to Toolbar ( Not menus )
                If tBar.Name.ToUpper().IndexOf("TOOLBAR") <> -1 Then
                    RemoveToolBar = tBar.ControlCollection(urn)
                    If Not RemoveToolBar Is Nothing Then
                        tBar.ControlCollection.Remove(RemoveToolBar)
                    End If
                End If
            Next


        Catch ex As Exception
            Throw New Exception("ACTAPPFunctions:RemoveToolBarItem", ex)
        End Try

    End Sub 'RemoveToolBarItem

-- Jim Durkin