I have a layer feature table with fields joined from a plugin datasource. How can I programmatically change the number format on a joined field?
Hi,
You need to set NumberFormat property in layer field description:
var fieldDescriptions = featureLayer.GetFieldDescriptions(); foreach (var fieldDescr in fieldDescriptions) { if (!fieldDescr.IsVisible || fieldDescr.Name == shapeField) continue; if(fieldDescr.Type == FieldType.Integer) { var custNumbFormat = new CIMCustomNumberFormat(); custNumbFormat.FormatString = "###-##-####"; fieldDescr.NumberFormat = custNumbFormat; } } featureLayer.SetFieldDescriptions(fieldDescriptions);
Apologies I missed that line in your original post. Works as expected now.
You need to set back field descriptions after modifying using SetFieldDescriptions method.
The code shown below is after a join. I do not see a change to the formatting in the attribute table after this executes.
var layerDef = layer.GetDefinition() as CIMFeatureLayer; JoinLibrary.UpdateJoinTable(layerDef, oldTableName, newTableName); // setup join here layer.SetDefinition(layerDef); // Attempt to update numeric format var fieldDescriptions = layer.GetFieldDescriptions(); foreach (var fieldDescr in fieldDescriptions) { if (fieldDescr.Type == ArcGIS.Core.Data.FieldType.Double) { var custNumbFormat = new CIMNumericFormat(); custNumbFormat.ZeroPad = true; custNumbFormat.RoundingValue = 6; fieldDescr.NumberFormat = custNumbFormat; } }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.