How to change field visibility and alias

701
3
Jump to solution
05-25-2019 04:44 PM
Suleyman-Arslan
Occasional Contributor

I am trying to iterate layers and change visibility of fields in feature layers. I tryed to get "CIMFieldDescription" but it returns null when layer has default field descriptions.

Am I going in wrong way?

Tags (1)
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi

The best way to change the visibility of a field to use the IDisplayTable.

This code will set all the fields in a layer to be visible:

 var table  = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault() as IDisplayTable;
            QueuedTask.Run( () => {
                var fieldDescriptions = table.GetFieldDescriptions();
                foreach (var field in fieldDescriptions)
                {
                    field.IsVisible = true;
                }

                table.SetFieldDescriptions(fieldDescriptions);
            });

Thanks

Uma

View solution in original post

3 Replies
Suleyman-Arslan
Occasional Contributor

I used following code to change visibility but nothing changed on layers.

Map pmap = await FindOpenExistingMapAsync(tb_Map.Text);

List<BasicFeatureLayer> featureLayerList = pmap.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().ToList();
listView1.ItemsSource = pmap.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().ToList();

foreach (BasicFeatureLayer fl in featureLayerList)
{
   await QueuedTask.Run(() =>
   {
      foreach (FieldDescription fd in fl.GetFieldDescriptions())
      {
            fd.IsVisible = true;
         fd.Alias = myconfig.Alias;
      }

   });

}

0 Kudos
UmaHarano
Esri Regular Contributor

Hi

The best way to change the visibility of a field to use the IDisplayTable.

This code will set all the fields in a layer to be visible:

 var table  = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault() as IDisplayTable;
            QueuedTask.Run( () => {
                var fieldDescriptions = table.GetFieldDescriptions();
                foreach (var field in fieldDescriptions)
                {
                    field.IsVisible = true;
                }

                table.SetFieldDescriptions(fieldDescriptions);
            });

Thanks

Uma

Suleyman-Arslan
Occasional Contributor

Thank you for your help.

Your code help me to find out my mistake. My code worked by adding code "fl.SetFieldDescriptions(fieldDesc);"

            Map pmap = await FindOpenExistingMapAsync(tb_Map.Text);
            List<BasicFeatureLayer> featureLayerList = pmap.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().ToList();
            foreach (BasicFeatureLayer fl in featureLayerList)
            {
                await QueuedTask.Run(() =>
                {
                    var fieldDesc = fl.GetFieldDescriptions();
                    foreach (var fd in fieldDesc)
                    {                 
                        fd.IsVisible = myconfig.Visible;
                        fd.Alias = myconfig.Alias;  
                    }
                    fl.SetFieldDescriptions(fieldDesc);
                });
                
            }
0 Kudos