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?
Solved! Go to Solution.
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);
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);
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;
}
}
You need to set back field descriptions after modifying using SetFieldDescriptions method.
Apologies I missed that line in your original post. Works as expected now.