1

I want to select the workspace and the dataset from the same dialog and this is my code for the workspace:

 private IWorkspace BrowseForWorkspace(int hwnd) {

            IGxDialog gxDlg = new GxDialogClass();
            gxDlg.ObjectFilter = new GxFilterWorkspacesClass();      
            gxDlg.AllowMultiSelect = false;

            IEnumGxObject workspaces;
            IWorkspace ws = null;

            if (gxDlg.DoModalOpen(hwnd, out workspaces) && workspaces != null) {
                IGxObject gxObj = workspaces.Next();
                if (gxObj is IGxDatabase) {
                    var gxDb = gxObj as IGxDatabase;
                    ws = gxDb.Workspace;
                } else if (gxObj is IGxFolder) {

                    IWorkspaceFactory wsf = new ShapefileWorkspaceFactoryClass();
                    ws = wsf.OpenFromFile(((IGxFile)gxObj).Path, hwnd);

                } 
                Marshal.FinalReleaseComObject(workspaces);
            }
            gxDlg.InternalCatalog.Close();
            Marshal.FinalReleaseComObject(gxDlg);
            return ws;

        }

and this is my code for the dataset:

private IDatasetName Browse(int hwnd) {

        IGxDialog gxDlg = new GxDialogClass();
        gxDlg.ObjectFilter = new GxFilterDatasetsAndLayersClass();
        gxDlg.AllowMultiSelect = false;
        IEnumGxObject workspaces;
        IDatasetName datasetName = null;

        if (gxDlg.DoModalOpen(hwnd, out workspaces) && workspaces != null) {

            var gxObj = (IGxDataset)workspaces.Next();
            if (gxObj != null) {
                var dataset = gxObj;
                datasetName = dataset.DatasetName;
            }
            Marshal.FinalReleaseComObject(workspaces);
        }
        gxDlg.InternalCatalog.Close();
        Marshal.FinalReleaseComObject(gxDlg);
        return datasetName;

    }

How do I link them together?

1

I believe you want to create a custom object filter. Here is a discussion over on the ESRI forum that took place 10 years ago. They talk about custom file extensions but you should be able to adapt the code to deal with workspaces and datasets.

My question is why? They are fundamentally different, ones a "container" of datasets the other is the dataset. I think trying to make your dialog "generic" is going to be problematic as you then need to test that the user has selected a valid object.

1
  • If, for some reason, your're not picky you can browse for generic GxObjects and then work out what they are later. Unfortunately this approach allows the user to 'see' and select any sort of object that would normally be visible in ArcCatalog so doesn't help limit the choices which is often a good idea in 'browse for' dialogs (not show unselectable objects to help the user find the right one). Normally I would have two browsers on different buttons: Browse for workspace, Browse for feature. It's not that unusual though, similar 'file or folder' questions have been asked on SO. Sep 13 '15 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.