I have created add-in toolbar with C# arcobjects. I am creating some empty geodatabase shapefiles. While creating featureclass i want to assign some default value to attribute and then make it read-only so user can not modify that value later.

IField field = new ESRI.ArcGIS.Geodatabase.FieldClass();
IFieldEdit fieldEdit= (ESRI.ArcGIS.Geodatabase.IFieldEdit)field ;
fieldEdit.Name_2 = "something"
fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;
fieldEdit.Length_2 = 10;
fieldEdit.DefaultValue_2 = "yes";

when i set fieldEdit.Editable_2 = false, then in attribute table, i see default value null instead of "yes", field is non editable.

I want field value as yes and non editable. Any suggestions?


I don't think this is possible. Certainly not with shapefiles. The IFieldEdit documentation itself states:

The IFieldEdit interface is used when creating new fields. You should not use it to modify fields, for that purpose use IClassSchemaEdit.

and the Editable property in both IFieldEdit and IFieldEdit2 (which superceded it) both state (emphasis added):

Editable | Indicates if the field can be edited. This should always be set to true.

Logically, only the objectid column of file geodatabase and the SDE-set rowid columns in enterprise geodatabases could have Editable = false, and even then there's no ArcObjects-supported way to pick and choose on columns on a per-row basis, even in databases which support column-level permission models. Shapefiles are all strictly O/S permission at the feature class level, and file geodatabase at the workspace level.

  • I agree. However how about ObjectID field which is created by default. It has unique value and non-editable? – IshaniP Oct 20 '14 at 5:34

Have a look at the interface IFieldInfo3 it has a property called ReadOnly, you can get to this object via the ITableFields interface.

As I understand the object model you are getting the FieldInfo object from say a FeatureLayer and not a FeatureClass. So turning ReadOnly to True is changing how the field is presented when as a layer object and not the source table (e.g. a geodatabase featureclass).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.