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?
-
2The 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– Michael Stimson2015年03月10日 04:04:42 +00:00Commented 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? ;-)EleventhDoctor– EleventhDoctor2015年04月01日 16:23:08 +00:00Commented Apr 1, 2015 at 16:23
-
1I 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– Michael Stimson2015年04月01日 22:16:36 +00:00Commented Apr 1, 2015 at 22:16
1 Answer 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!
Explore related questions
See similar questions with these tags.