0

I have a C# .NET application referencing ArcGIS Engine 10.2.

The last line of this fragment of code causes a COM Exception:

gridLayer = new FeatureLayerClass();
gridLayer.FeatureClass = layersFeatureWorkspace.OpenFeatureClass(layerName);
gridLayer.Name = "Density Grid";
gridLayer.Cached = true;
gridLayer.Selectable = true;
gridLayer.ShowTips = true;
gridLayer.DisplayField = "NumEvents"; // Causes COM exception immediately!

The COM error code is -2147467259, which doesn't appear in this list of error ranges: http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//0001000002zz000000

What is going on here and how can I resolve the issue?

  • 2
    The only thing I can think of is that the field NumEvents doesn't exist in the table, perhaps you're using an alias and not a field name; is it important to set the DisplayField? Unless there's a specific reason you need it set it can be left off and some generic field will be chosen. After the layer has been added to the map you can then go back and try to set it (but be very sure that the field exists using gridLayer.FeatureClass.FindField("NumEvents") >= 0. – Michael Stimson Mar 10 '15 at 4:04
  • @MichaelMiles-Stimson I tried setting the DisplayField after the layer was set up, which worked! Thank you! Do you want to post an answer for me to accept? ;-) – EleventhDoctor Apr 1 '15 at 16:23
  • 1
    I think you should answer your own question expanding on that comment with your working code, get yourself some Rep... I don't have time at the moment, Easter is upon us with two short weeks but the same amount of work needs to be done. I'll check back later to see your answer. – Michael Stimson Apr 1 '15 at 22:16
1

In this case the field NumEvents was not available until the DisplayRelationship was set up.

gridLayer = new FeatureLayerClass();
gridLayer.FeatureClass = layersFeatureWorkspace.OpenFeatureClass(layerName);
gridLayer.Name = "Density Grid";
gridLayer.Cached = true;
gridLayer.Selectable = true;
gridLayer.ShowTips = true;

[...]

// Create relationship between map layer and database table

IMemoryRelationshipClassFactory memRelFactory = new MemoryRelationshipFactoryClass();
IRelationshipClass relationshipClass;
relationshipClass = memRelFactory.Open(...);

// Perform a join between Layer table and map support database table
IDisplayRelationshipClass displayRelationship;
displayRelationship = (IDisplayRelationshipClass)gridLayer;
displayRelationship.DisplayRelationshipClass(releationshipClass, esriJoinType.esriLeftInnerJoin);

gridLayer.DisplayField = "NumEvents"; // No COM exception this time!
|improve this answer|||||

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.