Possible to create a new column in Outlook explorer view (Inbox explorer) with checkbox?

Add-in Express™ Support Service
That's what is more important than anything else

Possible to create a new column in Outlook explorer view (Inbox explorer) with checkbox?
 
Jonathan Gilpin




Posts: 50
Joined: 2012-12-11
I'm trying to add a custom UserProperty (which works succesfully) to a MailItem. I want to display whether this property is true or false. The property type is a OlUserPropertyType.olYesNo, however I cannot seem to make the View display a checkbox. Ideally, I'd be able to show my own Icon, but all my forum searches here have led me to believe Microsoft sucks and doesn't allow that property to be set.

Any thoughts on just getting a checkbox icon showing up?

Thanks.

P.s. love you guys.
Posted 27 Jan, 2013 19:14:13 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Hi Jonathan,

Below is the code fragment which works just fine in Outlook 2007-2010. It seems you cannot achieve this in Outlook 2013 32bit: whatever I do programmatically and manually in the UI, it shows Yes / No instead of checkbox.

Outlook.Explorer explorer = OutlookApp.ActiveExplorer();
Outlook.Selection selection = null;
try { selection = explorer.Selection; }
catch { }
if (selection != null)
{
    object item = selection[1];
    if (item is Outlook.MailItem)
    {
        Outlook.MailItem mail = item as Outlook.MailItem;
        Outlook.UserProperties userProperties = mail.UserProperties;
        Outlook.UserProperty userProperty = 
            userProperties.Add("My UserProperty", Outlook.OlUserPropertyType.olYesNo, true, Outlook.OlFormatYesNo.olFormatYesNoIcon);
        userProperty.Value = false;
        mail.Save();
        Marshal.ReleaseComObject(userProperty);
        Marshal.ReleaseComObject(userProperties);
        // no need to release mail because item and mail point to the same COM object, which is released below 
    }
    Marshal.ReleaseComObject(item);
    Marshal.ReleaseComObject(selection);
}
Marshal.ReleaseComObject(explorer);


)))


Andrei Smolin
Add-in Express Team Leader
Posted 28 Jan, 2013 06:37:18 Top
Jonathan Gilpin




Posts: 50
Joined: 2012-12-11
Hi Andrei, thanks for the fast reply. I think I'm doing exactly what you mention there, however the "checkbox icon" does not show up in "MyUserProperty" column, even when the property is set. The column shows up, but all values are blank. Am I missing something?

Here's my code:

public bool IsSpecialItem(MailItem item, bool bCreateProperty = true)
{
	UserProperties mailUserProperties = null;
	UserProperty property = null;
	
	bool bIsSpecialItem = false;
	try {
		if (item != null)
		{
			mailUserProperties = item.UserProperties;
			property = mailUserProperties.Find("MyUserProperty", true);
			if (property != null)
			{
				bIsSpecialItem = property.Value is bool && (bool)property.Value;
				property.Value = bIsSpecialItem;
			}
			else
			{
				bIsSpecialItem = MyUtils.IsItSpecial(item);
				if(bCreateProperty)
				{
					property = mailUserProperties.Add("MyUserProperty", OlUserPropertyType.olYesNo, true, OlFormatYesNo.olFormatYesNoIcon);
					property.Value = bIsSpecialItem;
					item.Save();
				}
			}
		}
	}
	catch (Exception ex)
	{
		bIsSpecialItem = false;
	}
	finally {
		if (mailUserProperties != null) Marshal.ReleaseComObject(mailUserProperties);
		if (property != null) Marshal.ReleaseComObject(property);
	}
	return bIsSpecialItem;
}
Posted 28 Jan, 2013 07:29:15 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Hi Jonathan,

You need to save the item whether the user property exists or not.


Andrei Smolin
Add-in Express Team Leader
Posted 28 Jan, 2013 07:34:19 Top
Jonathan Gilpin




Posts: 50
Joined: 2012-12-11
So if some MailItems don't have the property set, then nothing will show up in the column?
Do I need to create some bootstrap method to run one, that loops through all MailItems and sets the property to true/false for any to show up?

Thanks!

Jon
Posted 28 Jan, 2013 09:04:50 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Hi Jon,

Jonathan Gilpin writes:
So if some MailItems don't have the property set, then nothing will show up in the column?


Correct.

Jonathan Gilpin writes:
Do I need to create some bootstrap method to run one, that loops through all MailItems and sets the property to true/false for any to show up?


I can't say. This depends on the requirments that you implement.


Andrei Smolin
Add-in Express Team Leader
Posted 29 Jan, 2013 02:32:16 Top