Select to view content in your preferred language

C# Code for ArcGIS Pro Add-in to retrieve text string from selected record of a layer

391
0
11-05-2021 05:03 PM
JohnHanson1
New Contributor

Greetings,

Learning C# and I am looking for some code that will allow me to create a tool for the Map View, that when positioned over an individual polygon and selected by the tool, would return the text string (e.g. CntyGeo.lyrx) from the attribute field (say "Link") of the selected feature layer in the Contents Pane. 

I would use this returned individual text string to reference to another C# code that adds a .lyrx file to the Map View (see C# code below).  The text string would be used to add an .lyrx  from the C:\ drive  (e.g. CntyGeo.lyrx) to the Map View which currently works:

protected override void OnClick()
{
try { QueuedTask.Run(() => { Uri myUri = new Uri(@"C:\Temp\CntyGeo.lyrx"); Layer newlayer = LayerFactory.Instance.CreateFeatureLayer(myUri, MapView.Active.Map, LayerPosition.AddToTop); }); }
catch (Exception ex)
{
MessageBox.Show($@"Error: {ex.ToString()}");

}
I'm using ArcGIS Pro 2.8 and MS Visual Studio 2019.  Thanks for any help.

Regards,

John

0 Kudos
0 Replies