CommandbarCombobox problem

H

Hrishi

Hi,

I am developing a COM add-in using C#. I have a CommandbarCombobox and a
button on my outlook Add-in. I am opening a windows form when a user clicks
on the button. I have implemented the CommandbarCombobox change event and
opening the same windows form in the change event.
My problem is that, When user types in something into the combobox and tabs
out and hits enter on the button, two forms are opened. First one is opened
because of the button click event and the second one is opened because the
change event of the CommandbarCombobox is getting fired.

I just want to open one form for the button click event.

Any hints on how how to go about this?

Thanks,
Hrishi
 
K

Ken Slovak - [MVP - Outlook]

Pick one or the other of the 2 events to respond to, or set a flag to tell
that the form was already opened in one event, clear the flag when the form
closes. If both event handlers check that flag it would prevent both from
opening the form.
 
H

Hrishi

Thanks Ken.

One more query I had was, In the CommandbarCombobox the text is not
recognized until I hit enter or I tab out to some other control. Is there any
way around this behaviour? In my Add-in I have a CommandbarCombobox and a
button next to it. I want to enter text into the commandbarcombo and click on
the button next to it and display the text in the combo. But this is not
working. wonder how the Google Outlook Add-in does it.

Thanks
 
K

Ken Slovak - [MVP - Outlook]

Do you want to enter text manually or in code?

It would be better if you showed a snippet of your code to show what you're
doing.
 
H

Hrishi

Hi Ken,,

This is a code snippet where I am creating the CommandbarCombobox and
CommandbarButton:

//Commandbar Combobox
searchString = (CommandBarComboBox)PAMToolbar.Controls.
Add(MsoControlType.msoControlComboBox, missing, missing,
missing,
missing);
searchString.Style = MsoComboStyle.msoComboLabel;
searchString.Width = 200;
searchString.Caption = " Test";


//Button
CommandBarButton searchButton = (CommandBarButton)PAMToolbar.Controls.
Add(MsoControlType.msoControlButton, missing, missing,
missing,
missing);
searchButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
searchButton.Caption = "Tes Code";
searchButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.SearchButton_Click);
searchButton.BeginGroup = true;



When user clicks on Search button I am trying to display the text entered in
the CommandbarCombobox :

private void SearchButton_Click(CommandBarButton cmdBarbutton, ref bool
cancel)
{
MessageBox(searchString.Text);
}


Thanks,
 
K

Ken Slovak - [MVP - Outlook]

I think what's happening is that there are 2 modes for the combo, display
and edit. Unless tab or enter is pressed from within the combo when in edit
mode the display mode text isn't updated. At least that's my guess.

About the only thing I can think of is in your click event handler to call
the SetFocus method of the combo and then use SendKeys to send a tab or
enter keypress to the control. That should update the text value for the
Change event handler.
 

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