How Do I Add "Button" (Tool Strip Menu Item) To A Task Pane Tool Strip
-
Friday, April 13, 2012 2:34 PM
I'm using VS 2008 and programming with VB. I have created a Task Pane AddIn for Excel 2007. In this Task Pane I added a ToolStrip...in this ToolStrip I have a ToolStripDropDownButton. I have been trying to programmaticly add a "button" into this ToolStripDropDownButton. When I add this "button" manually it is called a ToolStripMenuItem instead of an actual button.
I have been able to programmaticly add a button...using user input from a textbox on form1...to the custom Ribbon with the following code:
Dim userFileName As String Dim NwBttn As New RibbonButton() Dim Menu1 As RibbonMenu userFileName = TextBox1.Text Menu1 = Globals.Ribbons.Ribbon1.Menu1 NwBttn.Label = userFileName NwBttn.Name = userFileName NwBttn.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeRegular Menu1.Items.Add(NwBttn) NwBttn.Visible = True NwBttn.Enabled = TrueBut, whenever I try to simulate this process for the Task Pane ToolStrip ToolStripDropDownButton I get no results at all.
'I've tried different options, like this Dim TSMI1 As New ToolStripMenuItem 'And like this Dim TSMI1 As New ToolStripButton 'And many different paths like this System.Windows.Forms.Item.AddRange(New System.Windows.Forms.ToolStripItem() {TSMI1})I don't know if I'm using the wrong type of controls for this or if the different paths I've tried are just way off.
All Replies
-
Monday, April 16, 2012 3:00 AMModerator
Hi fdegree,
Thanks for posting in the MSDN Forum.
Would you show more detail of your snippet for further research?
Have a good day,
Tom
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
-
Monday, April 16, 2012 9:52 AM
Thanks Tom...actually I decided to go a different route. I'm not going to use the Task Pane now
But, basically I couldn't dynamically add a button to the task pane. I read someplace on the internet that a button can not be added dynamically to a task pane...the task pane must have another container, to which a button could then be added...not sure if that's correct though.
Thanks Anyway...
-
Tuesday, April 17, 2012 7:12 AMModerator
Hi fdegree,
I would recommend you try following snippet. It work fine on my side.
ThisAddIn.vbPublic Class ThisAddIn Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup Dim Worksheet As Excel.Worksheet = Application.ActiveSheet For i As Integer = 1 To 10 Step 1 Worksheet.Cells(i, 1).Value = "Test " & CStr(i) Next CustomTaskPanes.Add(New UserControl1, "test").Visible = True End Sub Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown End Sub End ClassUserControl1.vb
Imports System.Windows.Forms Public Class UserControl1 Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim dropDown As ToolStripDropDown = New ToolStripDropDown() Dim button1 As ToolStripButton Dim Workbook As Excel.Workbook = Globals.ThisAddIn.Application.ActiveWorkbook Dim Worksheet As Excel.Worksheet = Workbook.ActiveSheet ToolStripDropDownButton1.DropDown = dropDown For i As Integer = 1 To 10 Step 1 button1 = New ToolStripButton button1.Text = Worksheet.Cells(i, 1).Value dropDown.Items.Add(button1) Next End Sub End ClassI hope it can help you.
Have a good day,
Tom
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by Tom_Xu_WXModerator Monday, April 23, 2012 8:11 AM

