Select to view content in your preferred language

How to use DefaultValues on IFields for FeatureClasses?

615
1
Jump to solution
03-08-2012 03:39 AM
SebastianKrings
Frequent Contributor
Hello,

I create a FeatureClass with some different Fields. After that I add a couple of Features to this FeatureClass.
One of the fields, called CreationDate, shall have every time the same value for all added Features where the other Fields-values will differ from each other.

I would really like to make use of the DefaultValue2 Property of the IField Interface to store that specific creation Date "automatically" for all features being added.
In my mind I would expect that when I add/ create a new feature in the FeatureClass and I do not set a value explicity for the Field "CreationDate" the DefaultValue will be used and stored on that Field.
The Problem is, after all, the Field "CreationDate" is still empty as I never had set it.

Thanks for any help.

Here some code I use for:

//Creating Fields to be added List<IField> fieldsToBeAdded = new...; addFields.Add(GISUtilities.GISUtilities.createNewField(tmp, esriFieldType.esriFieldTypeString, tmp, false, 100, dateString));  IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields;  //Add all Fields to be Added foreach (IField addField in fieldsToBeAdded) {     fieldsEdit.AddField(addField); }  featureClass= workspace.CreateFeatureClass(featureString, fields, null, null, abc.FeatureType, abc.ShapeFieldName, null);  //some Code which sets values explicity for all Fields except the field CreationDate (I debugged it, it is not set by mistake)  //Add Features using IFeatureCursor insertCursorAuswahl.InsertFeature(featureBufferAuswahl);   //After this statement I would expect the defaultValue Assigned, but my debug shows me still empty fields value = ""   //StopEditing and so workspaceEdit.StopEditing(true);  insertCursor.Flush(); return featureClass; 
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Honored Contributor
You have to call IRowSubtypes::InitDefaultValues in order to set default values on the new row.  There is an example in the developer help topic for this method.

View solution in original post

0 Kudos
1 Reply
NeilClemmons
Honored Contributor
You have to call IRowSubtypes::InitDefaultValues in order to set default values on the new row.  There is an example in the developer help topic for this method.
0 Kudos