In an add-in for Outlook that I’m developing I wanted to show the built in Color Categories dialog so that the user could choose categories in a familiar way. The categories should be set on an object that is unique for the add-in (aka not for a mail or calendar item). I couldn’t find any way to show the dialog itself and when searching Internet I found nothing useful, but I have found an acceptable workaround. On the AppointmentItem (or one of the others) there is a method called ShowCategoriesDialog which shows the dialog, so what I did was to create a temporary appointment item, setting my categories, showing the dialog, read the Categories property and then finally cleaning up. Here is the code:
private void ShowAllCategories()
{
Microsoft.Office.Interop.Outlook.Items items = IRM.TimeManager.Outlook.Globals.ThisAddIn.Calendar.Items;
Microsoft.Office.Interop.Outlook.AppointmentItem item = (Microsoft.Office.Interop.Outlook.AppointmentItem)items.Add();
try
{
item.Categories = MyObject.Categories ?? string.Empty;
item.ShowCategoriesDialog();
MyObject.Categories = item.Categories;
}
finally
{
if (item != null)
{
item.Delete();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(item);
}
if (items != null)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(items);
}
}