Code Snippet
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
GetData();
AddToolbar();
}
private void AddToolbar()
{
try
{
commandBar = Application.CommandBars["Report Toolbar"];
}
catch (ArgumentException e)
{
// Toolbar does not exist so we should create it.
}
if (commandBar == null)
{
// Add a commandbar
commandBar = Application.CommandBars.Add("Report Toolbar", 1, missing, true);
}
try
{
CatCombo = (Office.CommandBarComboBox)commandBar.Controls.Add(
Office.MsoControlType.msoControlDropdown, missing, missing, missing, missing);
CatCombo.Style = Office.MsoComboStyle.msoComboLabel;
for (int i = 0; i < dsFieldList.Tables.Count; i++ )
{ // the category name is stored in the first row of the table
CatCombo.AddItem(dsFieldList.Tables[i].Rows[0]["lname"].ToString(), missing);
}
CatCombo.ListIndex = 1;
CatCombo.DropDownLines = 15;
CatCombo.Width = 115;
CatCombo.Change += new Office._CommandBarComboBoxEvents_ChangeEventHandler(CatComboChange);
commandBar.Visible = true;
}
catch (ArgumentException e)
{
MessageBox.Show(e.Message);
}
}
private void CatComboChange(Office.CommandBarComboBox ctrl)
{
LoadComboItems(ctrl.Text);
}