Select to view content in your preferred language

Set Number Format on a layer attribute table

552
4
Jump to solution
12-14-2023 07:59 PM
KarlBeal
New Contributor II

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?

 

KarlBeal_0-1702612606097.png

 

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

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);

 

View solution in original post

0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

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);

 

0 Kudos
KarlBeal
New Contributor II

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;
    }
}

 

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

You need to set back field descriptions after modifying using SetFieldDescriptions method.

0 Kudos
KarlBeal
New Contributor II

Apologies I missed that line in your original post. Works as expected now.

0 Kudos