2

I am using ArcMap 10.4.1.

I cannot figure out how to properly initialize/create IAddDataDialog2 in C# to access a .gdb file in which I'm suposed to find a layer that I want to add in my TOC. I tried reading out the API from:

IAddDataDialog2 http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IAddDataDialog2_Interface/000v00000025000000/

IAddDataDialog http://help.arcgis.com/en/sdk/10.0/java_ao_adf/api/arcobjects/com/esri/arcgis/arcmapui/IAddDataDialog.html

AddDataDialog http://help.arcgis.com/en/sdk/10.0/java_ao_adf/api/arcobjects/com/esri/arcgis/arcmapui/AddDataDialog.html

But I still cannt figure it out.

EDIT: PolyGeo's request

 /// <summary>
 /// Do stuff.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="eventArgs">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void BoutonAjouterCoucheOnClique(object sender, EventArgs eventArgs)
 {
      ServiceAddDataDialog service = new ServiceAddDataDialog();
      service.OuvertureDuDialogAddData();
 }


/// <summary>
/// Service de support pour la fenêtre d'ajout de données.
/// </summary>
public class ServiceAddDataDialog
{
    /// <summary>
    /// Appelle l'ouverture de la fenêtre d'ajout de données.
    /// </summary>
    public void OuvertureDuDialogAddData()
    {
        IServicesDocumentMxd service = FabriqueServices.Instance.CreerPersisteur<IServicesDocumentMxd>();
        service.OuvrirAddDataDialog();
    }
}

/// <summary>
/// Persisteur pour les objets de type mxDocument
/// </summary>
internal class ServicesDocumentMxd : IServicesDocumentMxd
{
     /// <summary>
     /// Ouverture de la fenêtre d'ajout de données.
     /// </summary>
     public void OuvrirAddDataDialog()
     {
          IAddDataDialog dialog = new AddDataDialog();
          bool ouvert = false;
          dialog.Document = (IMxDocument)this.applicationInterne.Document;
          dialog.Map = (this.applicationInterne.Document as IMxDocument).Maps.get_Item(0);
          dialog.Show(this.applicationInterne.hWnd, ouvert);
     }
}

The code above actually open's up the Add Data dialog, i need to figure out how to gain access to any .gdb to look for the layer inside them.

EDIT: Me

It actually works with the code above, as for the first edit, I have'nt tested it out at that moment wich i just did... Just wanted to share the progress... I will then proceed to close this question later today.

  • What does your best code attempt look like? – PolyGeo Oct 29 '19 at 19:36
  • 1
    I don't believe the IAddDataDialog does anymore than allow to open it. The user then can browse allowable data types. If you want to filter the data types that the user is allowed to add, then you need to use GxDialog and apply a GxObjectFilter. – Rich Wawrzonek Oct 30 '19 at 17:59
  • In my context, the IAddDataDialog adds the layer in the TOC wich then the user can manipulate, that was the goal i was looking for by using IAddDataDialog, i do not need to manipulate the data in itself. – Sauce Brune Oct 31 '19 at 23:10
0

Like said in the question, I had trouble reading through the arcGIS IAddDataDialog APIs. After a few bumps, I have been able to open the AddDataDialog in wich I can then open a layer from any GDB.

public void OuvrirAddDataDialog()
{
     IAddDataDialog dialog = new AddDataDialog();
     bool ouvert = false;
     dialog.Document = (IMxDocument)this.applicationInterne.Document;
     dialog.Map = (this.applicationInterne.Document as IMxDocument).Maps.get_Item(0);
     dialog.Show(this.applicationInterne.hWnd, ouvert);
}

First you gotta instantiate a new AddDataDialog object and a bool object. Then the AddDataDialog REQUIRES the document that you are working with, the application, and also the maps from said document. In my case, I had an object called this.applicationInterne in wich it contained both the document and maps needed. From that you can call .Show() to open the dialog on any event.

PS: Like @Rich Wawrzonek has pointed out in the comment section of the question. This dialog only gives you the power to go and fetch any layer that you want, it does not give you the ability to filter the data types. For that matter you gotta use the GxDialog with a GxObjectFilter.

  • Thank you mods for the support. – Sauce Brune Nov 2 '19 at 16:40

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.