none
ActiveInspector() is not working in ribbon.cs RRS feed

  • Question

  • Hi

    In office 2007 i'm not getting ActiveInspector() in ribbon.cs. Below is the code :

    public bool getEnable(Office.IRibbonControl control)
            {
                Outlook.Inspector inspector = SingleOutlookRef.Instance.OutlookApp.ActiveInspector();
                object item = inspector.CurrentItem;
                
                //if(item is Outlook.ContactItem)
                //    MessageBox.Show("Contact");
                //else if(item is Outlook.AppointmentItem)
                //    MessageBox.Show("Appointment / Meeting");
                //else if (item is Outlook.TaskItem)
                //    MessageBox.Show("Task");
    
                bool Synced = SingleOutlookRef.Instance.IsSynced(item);
                return Synced;    
            }
    This is line i'm getting the error.  Error is " Object reference not set to an instance of an object "
    object item = inspector.CurrentItem;

    The same code is working for outlook 2010 32bit and 64bit

    thanks

    Bobbin

    Wednesday, October 17, 2012 9:02 AM

Answers

  • Are you calling Invalidate() or InvalidateControl() in your code at all to fire that getEnabled callback, or are you just relying on the callback firing only when the first contact item is opened and you're asked for the ribbon XML?
     
    What you need to do is use the Context property of the IRibbonControl object to get the Inspector and not use ActiveInspector().
     
    When NewInspector() fires the Inspector.CurrentItem reference is a weak object reference. It does not have all the properties filled in, all you should rely on is MessageClass and Class. You should wait for the first Activate() event that fires on the Inspector for all properties to be available. In that first Activate() event you should call Invalidate() or InvalidateControl() to fire the getEnabled() callback. At that time the newly opened Inspector will actually be ActiveInspector().

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Bobbin Paulose" <=?utf-8?B?Qm9iYmluIFBhdWxvc2U=?=> wrote in message news:31a8802c-6696-4716-b625-4ff80fee2a3f...

    Hi Ken

    Actually my aim is to enable or disable my custom button in the contact window. The custom button i created using Ribbon.XML. Code in the Ribbon.xml is below

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnLoad">
      <ribbon>
        <tabs>
          <tab idMso="TabContact">
            <group id="OutlookContact"
                   label="CRM">
              
              <button id="viewinCRM"
                             size="normal"
                             label="ViewInCRM"
                             screentip="ViewInCRM"
                             onAction="OnViewInCRM" getEnabled="getEnable"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    

    The function will trigger when we open a contact.

    Thanks

    Bobbin


    Ken Slovak MVP - Outlook
    Thursday, October 18, 2012 1:37 PM
    Moderator

All replies

  • When is this code firing? Is there actually an open item that could be an ActiveInspector()?
     
    What is the Inspectors.Count value at the time the code runs?
     
    If there is an Inspector, has it fired its initial Activate() event so you are sure ActiveInspector() would be valid?

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Bobbin Paulose" <=?utf-8?B?Qm9iYmluIFBhdWxvc2U=?=> wrote in message news:5d0104fd-a745-4595-88ea-5e29242a07c7...

    Hi

    In office 2007 i'm not getting ActiveInspector() in ribbon.cs. Below is the code :

    public bool getEnable(Office.IRibbonControl control)
            {
                Outlook.Inspector inspector = SingleOutlookRef.Instance.OutlookApp.ActiveInspector();
                object item = inspector.CurrentItem;
                
                //if(item is Outlook.ContactItem)
                //    MessageBox.Show("Contact");
                //else if(item is Outlook.AppointmentItem)
                //    MessageBox.Show("Appointment / Meeting");
                //else if (item is Outlook.TaskItem)
                //    MessageBox.Show("Task");
    
                bool Synced = SingleOutlookRef.Instance.IsSynced(item);
                return Synced;    
            }
    This is line i'm getting the error.  Error is " Object reference not set to an instance of an object "
    object item = inspector.CurrentItem;

    The same code is working for outlook 2010 32bit and 64bit

    thanks

    Bobbin


    Ken Slovak MVP - Outlook
    Wednesday, October 17, 2012 4:08 PM
    Moderator
  • Hi Ken

    Actually my aim is to enable or disable my custom button in the contact window. The custom button i created using Ribbon.XML. Code in the Ribbon.xml is below

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnLoad">
      <ribbon>
        <tabs>
          <tab idMso="TabContact">
            <group id="OutlookContact"
                   label="CRM">
              
              <button id="viewinCRM"
                             size="normal"
                             label="ViewInCRM"
                             screentip="ViewInCRM"
                             onAction="OnViewInCRM" getEnabled="getEnable"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    

    The function will trigger when we open a contact.

    Thanks

    Bobbin

    Thursday, October 18, 2012 9:45 AM
  • Are you calling Invalidate() or InvalidateControl() in your code at all to fire that getEnabled callback, or are you just relying on the callback firing only when the first contact item is opened and you're asked for the ribbon XML?
     
    What you need to do is use the Context property of the IRibbonControl object to get the Inspector and not use ActiveInspector().
     
    When NewInspector() fires the Inspector.CurrentItem reference is a weak object reference. It does not have all the properties filled in, all you should rely on is MessageClass and Class. You should wait for the first Activate() event that fires on the Inspector for all properties to be available. In that first Activate() event you should call Invalidate() or InvalidateControl() to fire the getEnabled() callback. At that time the newly opened Inspector will actually be ActiveInspector().

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Bobbin Paulose" <=?utf-8?B?Qm9iYmluIFBhdWxvc2U=?=> wrote in message news:31a8802c-6696-4716-b625-4ff80fee2a3f...

    Hi Ken

    Actually my aim is to enable or disable my custom button in the contact window. The custom button i created using Ribbon.XML. Code in the Ribbon.xml is below

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnLoad">
      <ribbon>
        <tabs>
          <tab idMso="TabContact">
            <group id="OutlookContact"
                   label="CRM">
              
              <button id="viewinCRM"
                             size="normal"
                             label="ViewInCRM"
                             screentip="ViewInCRM"
                             onAction="OnViewInCRM" getEnabled="getEnable"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    

    The function will trigger when we open a contact.

    Thanks

    Bobbin


    Ken Slovak MVP - Outlook
    Thursday, October 18, 2012 1:37 PM
    Moderator
  • Hi Ken

    Thanks for your fast reply. Its very helpful to get a small example regarding Invalidate().

    Thanks

    Bobbin

    Monday, October 22, 2012 2:19 PM
  • What you'd need to do is set up a reference to the Ribbon object when the Ribbon.OnLoad() event fires. That should be at a global level so it's accessible to your code and doesn't go out of scope. When you get the NewInspector() event to tell you an item has been opened, you can add an Activate() handler. Maintain a flag that starts out False and in Activate() check the flag. If False call Ribbon.Invalidate() or InvalidateControl(id) on a specific ribbon control. That will fire your getEnabled and other callbacks. In those callbacks Ribbon.Context will be the actual Inspector, just cast Context to Inspector.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Bobbin Paulose" <=?utf-8?B?Qm9iYmluIFBhdWxvc2U=?=> wrote in message news:79e2ecce-945c-46e3-92c6-7ce8136b9bc2...

    Hi Ken

    Thanks for your fast reply. Its very helpful to get a small example regarding Invalidate().

    Thanks

    Bobbin


    Ken Slovak MVP - Outlook
    Monday, October 22, 2012 2:28 PM
    Moderator