I am doing a tutorial here. Everything works fine with excel blank page
https://msdn.microsoft.com/en-us/library/bb608590(v=vs.120).aspx
When I load the excel sheet that someone gave me and presses the toggleButton1 button to show the panel that I get
{"The taskbar has been removed or otherwise no longer valid." }
on the line
private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.TaskPane.Visible = ((RibbonToggleButton)sender).Checked;
}
Is the pointer to this taskbar somehow going away?
Microsoft.Office.Tools.CustomTaskPane PartPhotoTaskPane;
Globals.ThisAddIn.Application.WindowActivate += Application_WindowActivate;
void Application_WindowActivate(Excel.Workbook Wb, Excel.Window Wn)
{
if (PartPhotoTaskPane != null)
{
PartPhotoTaskPane.Dispose();
InitalizePartPhotoViewerTaskPane(EPPF);
}
else
{
InitalizePartPhotoViewerTaskPane(EPPF);
}
}
private void InitalizePartPhotoViewerTaskPane(ExcelPartPhotoFunctions _EPPF)
{
try
{
PartPhotoTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(new PartPhotoSearchPane(_EPPF), "Part Information", Globals.ThisAddIn.Application.ActiveWindow);
PartPhotoTaskPane.Visible = Properties.Settings.Default.InfoPaneOpenStatus;
PartPhotoTaskPane.Width = 260;
}
catch (Exception e)
{
MessageBox.Show("Error starting Part Info Toolbar:" + Environment.NewLine +
e.Message + Environment.NewLine + e.StackTrace, "Error!", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
ATTEMPT 1:
Still an error in the click event. I assume this is due to the fact that I need to share this area between classes?
private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.TaskPane.Visible = ((RibbonToggleButton)sender).Checked;
}
private void ExcelEvents_WorkbookActivate(Excel.Workbook wb)
{
var taskPane = (customTaskPanes.Where(kvp => kvp.Key.Target == wb).Select(kvp => kvp.Value).FirstOrDefault());
if (taskPane == null)
{
UcCenlarInvest control = new UcCenlarInvest();
taskPane = this.CustomTaskPanes.Add(control, "My pane for workbook " + wb.Name);
customTaskPanes[new WeakReference(wb)] = taskPane;
}
}
ATTEMPT 2:
So now the Ribbon class can get TaskPane, but I still get the same error. Added:
private CustomTaskPane taskPane;
public CustomTaskPane TaskPane
{
get
{
return pane;
}
set
{
taskPane = value;
}
}
.....
TaskPane = (customTaskPanes.Where(kvp => kvp.Key.Target == wb).Select(kvp => kvp.Value).FirstOrDefault());