How To Make 'Reply' & 'Reply-All' Button Grey In Outlook C#

Smit Rathod 100 Reputation points
2023-01-11T09:12:38.6166667+00:00

In outlook…

  • If you select multiple email from top to bottom, Reply/Reply-all buttons are enabled
  • If you select multiple email from bottom to top, Reply/Reply-all buttons are disabled

CASE-1 : Selecting 'Test 2' & then select 'Test 1' => Reply/Reply-all buttons are enabled

enter image description here

CASE-2 : Selecting 'Test 1' & then select 'Test 2' => Reply/Reply-all buttons are disabled

enter image description here

I have Explorer.SelectionChange event which checks if there are multiple emails are selected. If there are multiple emails are selected, Then I have disabled 'Reply/Reply-All' events by MailItem.Actions["Reply"].Enabled = false;.

Explorer objExplorer = (Explorer)Api.Instance.GetActiveExplorer();
if (objExplorer != null)
{
    objExplorer.SelectionChange += () =>
    {
        Selection objSelectionList = objExplorer.Selection;
        if (objSelectionList != null && objSelectionList.Count > 1 && objSelectionList[1] != null)
        {
            MailItem objMailItem = objSelectionList[1] as MailItem;
            if (objMailItem != null)
            {
                objMailItem.Actions["Reply"].Enabled = false;
                objMailItem.Actions["Reply to All"].Enabled = false;
            }
        }
    };
}

But it's not giving me output like CASE-2. So basically I want to make both buttons disabled in CASE-1 as shown in CASE-2. It's only giving me a popup saying 'This action not available for this item'.

I have to do this to maintain consistency in both case. So need solution from one of below..

  • If there is any way to enable both buttons in CASE-2 (Like CASE-1)
  • If there is any way to disable both buttons in CASE-1 (Like CASE-2)

Thanks in advance.

Outlook
Outlook
A family of Microsoft email and calendar products.
3,319 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,562 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,680 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
5,035 questions
0 comments No comments
{count} votes

Accepted answer
  1. Eugene Astafiev 891 Reputation points
    2023-01-11T09:28:05.57+00:00

    In the code you disable the Reply and Reply to All actions on the first selected item which is a different item in both scenarios:

    MailItem objMailItem = objSelectionList[1] as MailItem;
    if (objMailItem != null)
    {
       objMailItem.Actions["Reply"].Enabled = false;
       objMailItem.Actions["Reply to All"].Enabled = false;
    }
    

    But the displayed item is always the same, but it is not necessary the first in the collection. So, instead I'd suggest iterating over all selected items and disabling actions for all of them to make sure the view is updated correctly. A raw sketch:

    for(int i=1; i <= objSelectionList.Count; i++)
    {
      MailItem objMailItem = objSelectionList[i] as MailItem;
      if (objMailItem != null)
      {
         objMailItem.Actions["Reply"].Enabled = false;
         objMailItem.Actions["Reply to All"].Enabled = false;
      }
    }
    

    That is because the first item is not visible in the UI (Test 1). In case of failures you can handle exceptions to suppress them and try on another item.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful