CommandBarComboBox Event not fired / triggered every time

T

TobyG

Hello

I have a CommandBarComboBox in a Toolbar and one button.

The events works fine in the first Word Document window.

On opening the 2't window the event onyl works for the button.
The event for the combobox will not longer triggered / fired in the 2't
window.
The event works in the 1st window.

Reassining the event does not solve the problem.

any ideas?
workarrounds? I need a DropDown Box.

thanks a lot





using System.Reflection;
using Microsoft.Office.Core;
using System.Windows.Forms;

namespace ToolbarAddInTest
{
internal class ToolbarController
{
private CommandBarButton cmdBtSave;
private CommandBar commandBar;
private Microsoft.Office.Interop.Word.Application applicationObject;
Microsoft.Office.Interop.Word._Document mytemplate;
private bool iscreate;

public ToolbarController(Microsoft.Office.Interop.Word.Application
applicationObject)
{
this.applicationObject = applicationObject;
CreateToolbar();
}

protected void CreateToolbar()
{
commandBar =
applicationObject.CommandBars.Add("Toolbar-Navigation",
MsoBarPosition.msoBarTop, System.Type.Missing, true);
commandBar.Visible = true;

if (commandBar.Visible == true)
{
cmdBtSave =
(CommandBarButton)commandBar.Controls.Add(MsoControlType.msoControlButton,
System.Type.Missing, "Speichern", System.Type.Missing, true);
cmdBtSave.Tag = "Speichern";
cmdBtSave.FaceId = 3;
cmdBtSave.Caption = "Save";
cmdBtSave.Enabled = true;
cmdBtSave.Click += cmdBtSave_Click;

MakeComboBox("DocumentSelect", ComboBox_Changed);
}
}

private void ComboBox_Changed(CommandBarComboBox ctrl)
{
MessageBox.Show("ComboBox" + ctrl.Id);
MessageBox.Show("ComboBox" + ctrl.Index);
MessageBox.Show("ComboBox" + ctrl.Text);
}

public CommandBarComboBox MakeComboBox(string id,
_CommandBarComboBoxEvents_ChangeEventHandler handler)
{
object temporary = true;
object missing = Missing.Value;
CommandBarComboBox cbCb =
(CommandBarComboBox)commandBar.Controls.Add(

MsoControlType.msoControlDropdown, missing, missing, missing,
temporary);
cbCb.Style = MsoComboStyle.msoComboLabel;
cbCb.AddItem("itm 1", missing);
cbCb.AddItem("itm2", missing);
cbCb.DropDownLines = 20;
cbCb.DropDownWidth = 420;
cbCb.ListHeaderCount = 0;
cbCb.Width = 220;
if (handler != null)
{
cbCb.Change += handler;
cbCb.Tag = id;
}
cbCb.Enabled = true;
return cbCb;
}

void cmdBtSave_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
MessageBox.Show("Save");
}
}
}

using Office = Microsoft.Office.Core;

namespace ToolbarAddInTest
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
new ToolbarController(this.Application);
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top