BillyBuerger

IGxPreview with non-previewable selection

Discussion created by BillyBuerger on Jan 25, 2011
I have a custom zoom tool that I use in ArcMap and I decided to make it work in catalog as well.  Overall it was simple enough.  But I ran into a problem when you select an item in catalog that doesn't have a preview. (It states "The selection cannot be previewed.")  When I try to get the IScreenDisplay or IActiveView, IGxPreview throws an exeption on all of its properties.  I don't see anything that tells me whether the selected object is previewable or not.  Right now, I just have a try/catch on it.  That works but is ugly and when I'm debugging shows a whole lot of exceptions in the output window.  Anyone have any ideas?  The best I can think of is to look at the selected object and see if it's a type that I know has a preview.  But I was expecting there to be something to tell me this.  Here's my code for getting the IActiveView and a comment where the error occurs...

IActiveView View = null;

if (m_pApplication is IMxApplication)
{
   View = ((IMxDocument)m_pApplication.Document).ActivatedView;
}
else if (m_pApplication is IGxApplication)
{
   IGxApplication gxApp = (IGxApplication)m_pApplication;

   if (gxApp.View is IGxPreview)
   {
      IGxPreview gxPreview = (IGxPreview)gxApp.View;

      // This crashes
      if (gxPreview.View is IGxGeographicView2)
      {
         IGxGeographicView2 gxView = (IGxGeographicView2)gxPreview.View;
         View = gxView.ActiveView;
      }
   }
}

Outcomes