BenDowling

I want to display several ComboBoxes on an Outlook PropertyPage. I want the ComboBoxes to display icons and text.

I've tried two approaches to this: Setting the draw mode of a standard ComboBox to DrawMode.OwnerDrawFixed and then setting a DrawItem callback. However the callback never gets called. I then tried extending the standard ComboBox class that sets the draw mode in the constructor and overrides OnDrawItem. This method never gets called.

I can only conclude that the DrawItem event never gets fired. Is this something to do with the ComboBox being inside a PropertyPage

Any suggestions on how this can be resolved

Many thanks,

Ben


Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

BenDowling

To see if the ProprtyPage was causing the problem I've tried displaying the UserControl in a form, and I get the same problem. The DrawItem callback isn't get invoked for lists or comboboxes, even though the DrawMode is set to owner.

Has anyone seen this problem before, and do you know of a solution

Thanks again,

Ben




Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

BenDowling

I also post this problem to the Windows.Forms group, but they're pretty sure that it is an Outlook problem:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=2009602&SiteID=1&mode=1

Any suggestions how how to do custom drawing of lists and combo boxes in an outlook addin

Thanks, Ben




Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

Ji Zhou ¨C MSFT

Hi Ben,

Strange! In my side, both in Winform application and Outlook PropertyPage , the callback function of DrawItem can be reached. I just test using a MessageBox.Show() in the comboBox1_DrawItem() method. Once I manipulate the ComboBox in runtime, a MessageBox pops up for several times according to the Items¡¯ Count of ComboBox. The only difference is I add the Items in design time, not set its DataSource in runtime. So I think problem may exists in where we set DataSource. Can you post more codes about that

Also, there is a good example to show how to create comboBox with Image, refer this link please: http://www.codeproject.com/cs/miscctrl/ImageComboBoxControl.asp

Hope this information can help!

Thanks

Ji






Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

BenDowling

Interesting! At least it's not an Outlook limitation then.

I've modified my code so use Items.Add instead of setting the DataSource and the problem remains. Here is the current
code:


Code Snippet

// in init

comboBox.DropDownStyle = ComboBoxStyle.DropDownList;

comboBox.Items.Add("Test 1");
comboBox.Items.Add("Test 2");
comboBox.Items.Add("Test 3");
comboBox.Items.Add("Test 4");

comboBox.DrawMode = DrawMode.OwnerDrawFixed;
comboBox.DrawItem += new DrawItemEventHandler(comboBox_DrawItem);


private void comboBox_DrawItem(object sender, DrawItemEventArgs e)
{
MessageBox.Show("Draw called!");
}






Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

BenDowling

I've created a Windows Forms application with the same code and the callback gets invoked without any problems. Maybe it is an outlook issue I'm developing for Outlook 2003 with VSTO2005SE.




Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

Ji Zhou ¨C MSFT

OK. I test it on Outlook 2007 with VSTO2005 SE, and find no problem. And I will try to find a machine with same environment as yours to have a test. Later to get back to you :-)

Thanks

Ji






Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

Ji Zhou ¨C MSFT

Hi Ben,

I do not think this is an Outlook Add-in issue. I tried both Outlook Add-in developed by VSTO and VSTO SE in Visual Studio 2005. But I still cannot reproduce your scenario.

These are the main steps I performed:

1. Create a new Outlook 2003 Add-in project with VSTO SE;

2. Add an UserControl1 to the project created before;

3. Drag a comboBox named comboBox on the UserControl1, then double click the UserControl1 and copy your codes before comboBox_DrawItem into UserControl1_Load method. Copy whole of your comboBox_DrawItem() into the UserControl1 Class as a method.

4. Implement the Outlook.PropertyPage interface for your UserControl. And register the ComVisiable attribute to true of UserControl1 Class.

5. In ThisAddin_Startup, add event to this.Application.OptionsPagesAdd event. In the event handle, use Pages.Add(new UserControl1(), ¡°Test¡±).

6. Run the solution. When I navigate to new added OptionPage, MessageBox shows up with information ¡°Draw called¡±.

If I have any misunderstanding about steps to reproduce your issue, please feel free to point it out.

Still, I think error should exist in your codes of UserControl. If you can reproduce it in minimum codes, and post all of them here. That will be more helpful for us to locate the problem.

Thanks

Ji






Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

BenDowling

Hi Ji,

Thanks for looking into this. I'm no longer using a PropertyPage, but the problem still remains. Is there anything else that might cause this problem

Thanks, Ben




Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

BenDowling

I've created a new Outlook project in VS. It contains the minimal code to add a toolbar to the explorer with one button. Clicking on the button displays a form. The form contains a list which has a draw mode of ownerDrawFixed. The same problem persists: I am not getting any DrawItem events.

I'm using exactly the same form as I've used for a stand alone project, and that was getting the events without any problems. The button click handler on the explorer toolbar is:

Code Snippet

Form form = new Form();

form.ShowDialog();



As I said, the actual form code was all working when it was a standalone windows application. Does anyone have any ideas

Is there any way I can monitor what events are getting fired externally and find out what might be happening



Thanks in advance,
Ben




Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

BenDowling

I thought I'd try creating the form in a new thread - and suddenly I'm getting DrawItem events!! I changed the prevois code snippet to:

Code Snippet

// In explorer toolbar button click event handler

Thread t = new Thread(showForm);

t.start();


private void showForm()

{

Form form = new Form();

form.ShowDialog();

}


and it all works! It's really strange that by not displaying the form on a seperate thread it doesn't get DrawItem events, but everything else seems to be OK! Anyone know why

Cheers, Ben




Re: Visual Studio Tools for Office ComboBox on an Outlook PropertyPage doesn't seem to get DrawItem events

Ji Zhou ¨C MSFT

Hi Ben,

First, very glad to hear about that your problem are resolved. But very strange, I write the codes in Outlook without put them in a new thread, also works. I still cannot think out any reason caused in such weird behavior, maybe some specific setting ignored by us related to environment

J Second, thank you for sharing the solution, nice guy! It will benefit others in future probably.

Thanks

Ji