Getting an object from an ArcCatalogue selection

Discussion created by patrickria on Sep 18, 2011
Latest reply on Sep 19, 2011 by agray1

I'm trying to get a hold of the object corresponding to the item(s) selected in the ArcCatalogue tree or contents window. However it doesn't seem to work as I would expect.

For example,

        ApplicationCat = (ESRI.ArcGIS.CatalogUI.IGxApplication)ArcCatalog.Application;
        IGxSelection Selected;
        IEnumGxObject SelectedObjects;
        IGxObject SelectedObject;
            //get the selection of the contents window
            Selected = ApplicationCat.Selection;
            if (Selected.Count > 0)
                SelectedObjects = Selected.SelectedObjects;
                //loop through the selection
                while ((SelectedObject = SelectedObjects.Next()) != null)
                   IName ObjectType = Dataset.InternalObjectName;

Whenever I use this approach, either from the Selection or SelectedObject properties of IGxApplication the InternalObjectName property of the resulting IGxObject is null (the NameString property is an empty string).

I'm quite new to all this, but it seems like this is a sensible approach. Any ideas would be greatly appreciated.