I'm trying to create my first Excel AddIn and want to have a CheckBox which is checked when my custom Ribbon is loaded.
I've everything working as needed EXCEPT this and I've spent a lot of time in getting this to work for my solution in C#, so any help is greatly appreciated.
using System.Diagnostics;
using System.Runtime.InteropServices;
using ExcelDna.Integration;
using ExcelDna.Integration.CustomUI;
using MyRepository;
namespace My.Excel
{
[ComVisible(true)]
public class Ribbon : ExcelRibbon, IExcelAddIn
{
private MyRepository _myRepository;
private bool _suppressWarningsCheckBoxState;
public void AutoOpen()
{
_suppressWarningsCheckBoxState = true;
_myRepository = new MyRepository();
Functions.MyRepository = _myRepository;
}
public void AutoClose()
{
//throw new NotImplementedException();
}
public override string GetCustomUI(string ribbonId)
{
return @"
<ribbon>
<tabs>
<tab id=""TabPod"" label=""POD Tools"">
<group id=""Group1"" label=""Engineering Tools"">
<checkBox id=""CheckBoxAutoUpdate"" label=""Auto Update"" enabled=""true"" onAction=""OnAutoUpdateChanged""/>
<checkBox id=""CheckBoxSuppressWarnings"" label=""Suppress Warnings"" enabled=""true"" getPressed=""OnSuppressWarningsPressed"" onAction=""OnSuppressWarningsChanged""/>
<button id=""ButtonCustomDialog"" label=""Show Custom Dialog"" onAction=""OnButtonClicked""/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>";
}
public void OnRibbonLoad(IRibbonUI sender)
{
_suppressWarningsCheckBoxState = true;
sender.InvalidateControl("CheckBoxSuppressWarnings");
}
public void OnSuppressWarningsPressed(IRibbonControl control,ref bool pressed)
{
pressed = _suppressWarningsCheckBoxState;
}
public void OnAutoUpdateChanged(IRibbonControl control, bool pressed)
{
Functions.SetAutoUpdate(pressed);
}
public void OnSuppressWarningsChanged(IRibbonControl control, bool pressed)
{
Functions.SetSuppressWarnings(!pressed);
}
public void OnButtonClicked(IRibbonControl control)
{
Functions.CustomDialog();
}
}
}