Set Field IsVisibe to false ArcGIS Pro SDK

699
1
10-17-2018 02:51 AM
GARYLESTER
New Contributor

I am trying to hide some fields with an add-in. The documentation says that the IsVisible property for a FieldDescriptions object can be get or set. I am coming from python so I am not sure if setting the property is quiet the same in c#.

Here is link to IsVisible porperty ArcGIS Pro 2.2 API Reference Guide 

Here is the code I have so far

internal class Hide : Button
    {
        protected async override void OnClick()
        {
            await HideFields();
        }
        public Task HideFields()
        {
            return QueuedTask.Run(() =>
            {
                List<string> fieldList = new List<string>() { "NORTH","EAST","HRMS","PDOP","SATELLITES","LATITUDE","LONGITUDE","PHOTO","PRODUCT_TYPE","LINE_TYPE","AFE","FILE_NAME","WELD_TYPE","WELD_LOCATION","XRAY_PERCENTAGE"};
                var mapView = MapView.Active;
                var listLayers = mapView.Map.Layers.OfType<FeatureLayer>();
                foreach(var lyr in listLayers.ToList())
                {
                    
                    var fields = lyr.GetFieldDescriptions().Where(f => fieldList.Contains(f.Name, StringComparer.OrdinalIgnoreCase));
                    foreach(var field in fields)
                    {
                        FieldDescription fieldDesc = field;
                        fieldDesc.IsVisible=false;

                    
                        //MessageBox.Show(field.Name.ToString());
                    }
                }
            });
        }
    }
0 Kudos
1 Reply
by Anonymous User
Not applicable

Hi Gary - 

Did you resolve this issue? 

It looks like you had it, save but one line of code. 

In fact your snippet helped me, so thank you! 

Basically i think you could add "lyr.SetFieldDescriptions(fields);" to line 23. 

The method is also mentioned here, so thank you, too, Uma Harano @UHarano-esristaff

https://community.esri.com/thread/234346-how-to-change-field-visibility-and-alias 

Good Luck! 

+ bill 

0 Kudos