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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 5, 2015 at 10:39
3
  • 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. Commented Mar 10, 2015 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? ;-) Commented Apr 1, 2015 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. Commented Apr 1, 2015 at 22:16

1 Answer 1

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!
answered Apr 2, 2015 at 8:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.