Drag and Drop functionality in ArcGIS Pro SDK

430
3
01-01-2024 02:02 AM
AbhijeetNandeshwar1
New Contributor II

Hi Everyone,

I am trying to build a custom UI for a geoprocessing tool using DockPane.

I am populating a textbox or combo box using drag and drop functionality. By referring to the documents and sample I am able to access the feature class in the binding variable "TOCContent". I am unaware how can I access the attribute field of that particular feature class.

Any insights or guidance would be appreciated.

Below is the code copied from ESRI's sample (amended slightly).  

public override void OnDrop(DropInfo dropInfo)
 {
  await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
 {
  if (dropInfo.HasTOCContent())
  { 
      var layers = dropInfo.GetTOCContentOfType<FeatureLayer>();             
      FeatureLayer featureLayer =layers.FirstOrDefault();
   //  TOCContent = featureLayer.GetPath().ToString();
          TOCContent = featureLayer;
          var featureclass = featureLayer.GetFeatureClass();
          var field = featureclass.GetDefinition().GetFields();
          TableContent= field.findfield();
     }  
 }
Data binding implementation:

   private string _tocContentInfo = "Drag and drop from TOC";
   public string TOCContent
   {
       get { return _tocContentInfo; }
       set
      {
           SetProperty(ref _tocContentInfo, value, () => TOCContent);
      }
   }

Below is a screenshot of my goal.

Thanks,

Abhijeet

AbhijeetNandeshwar1_0-1704103332779.png

 

Tags (1)
3 Replies
CharlesMacleod
Esri Regular Contributor

>I am unaware how can I access the attribute field of that particular feature class.

1. Select/Search for the row(s) u want to retrieve from the feature class

2. Loop through the rows in the row cursor retrieving the value(s) from each row using either the name of the field or a field index (retrieved from FindField). FindField is useful for situations where u dont know if the returned rows contains the field u r looking for - in that case it will return "-1" rather than a 0-based field index.

A good place to start learning more is here - this section of the GDB concept doc goes into quite some detail on how to select and search for rows and the pattern to use to retrieve attribute values:

https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Geodatabase#querying-data 

 

 

AbhijeetNandeshwar1
New Contributor II

Hello Charles,

Thank you for the workflow. I did go through the documentation. I am able to get the list of fields however, I am having trouble with binding the list of fields with the combo box which we have in our dockpane. Our attribute table has 3 fields named ObjectID[0], Shape[1] and elevation[2]. I want to populate my combo box with the elevation fields. Can you please help me with the workflow or any suggestion?

 

 public override async void OnDrop(DropInfo dropInfo)
 {
      //Summary//
    //Same as above in the post from line number 3 to 11
  //Summary//

            FeatureClassDefinition featureClassDefinition = featureclass.GetDefinition();
           IReadOnlyList<ArcGIS.Core.Data.Field> listOfFields = featureClassDefinition.GetFields();

      }
}
        private FeatureLayer _tocContentInfo;
        public FeatureLayer TOCContent
        {
            get { return _tocContentInfo; }
            set
            {
                SetProperty(ref _tocContentInfo, value, () => TOCContent);
            }
        }

        public IReadOnlyList<ArcGIS.Core.Data.Field> Fields
        {
            get { return listOfFields; }
        }

}

 

 

Thanks,

Abhijeet 

0 Kudos
CharlesMacleod
Esri Regular Contributor

in the code snippet, I see two potential issues:

1. "Fields" property is defined as List of "Field" - unless u have a data template defined, I would change it to List<string> and store the field _name_ or alias rather than the field object itself.

2. U may need to add a manual property notification event after u change the list of field (names). So something like - NotifyPropertyChanged("Fields") right after listOfFields is updated - this alerts the binding that the list has changed and will refresh the combo box contents.