I can add a table as an XYEventSource from an Access database, with the following code. This works. My problem is described after the code block.
The problem I'm having is that it's adding the table to the map as a feature layer with a feature class, and I don't want that. I want it to behave exactly as if the user right-clicked on the table in ArcMap and chose the "Display XY Data..." menu item.
Right-clicking on the layer created as above and choosing Properties shows this for the source:
Data Type: XY Event Source
Location: C:\data\database.mdb
Feature Class: MyTable_Features
Feature Type: Simple
Geometry Type: Point
However, if you conduct the Display XY Data operation manually in ArcMap on a standalone table added to the TOC, the following shows for the source, and this is what I'm after:
Data Type: XY Event Source
Location: C:\data\database.mdb
Table: C:\data\database.mdb\MyTable
X Field: myX
Y Field: myY
Has Object-ID Field: Yes
What in the world am I doing wrong?
Thank you for any assistance!
Mike
Code:
srWorkspace = ao.OpenAccessWorkspace(dataSource);
srTable = ao.OpenTable(srWorkspace, "MyTable");
IDataset dataSet = srTable as IDataset;
IName tableName = dataSet.FullName;
IXYEvent2FieldsProperties xyEvent2FieldsProperties = new XYEvent2FieldsPropertiesClass();
xyEvent2FieldsProperties.XFieldName = "myX";
xyEvent2FieldsProperties.YFieldName = "myY";
IXYEventSourceName xyEventSourceName = new XYEventSourceNameClass();
xyEventSourceName.EventProperties = xyEvent2FieldsProperties;
xyEventSourceName.EventTableName = tableName;
ftrLayer = new ESRI.ArcGIS.Carto.FeatureLayerClass();
SpatialReferenceEnvironment spatRefEnv = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
IGeographicCoordinateSystem geoCS = spatRefEnv.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
geoCS.SetFalseOriginAndUnits(-180, -90, 1000000);
xyEventSourceName.SpatialReference = geoCS as ESRI.ArcGIS.Geometry.ISpatialReference;
IName xyName = xyEventSourceName as IName;
IXYEventSource xyEventSource = xyName.Open() as IXYEventSource;
IStandaloneTableCollection pTableCollection = map as IStandaloneTableCollection;
IStandaloneTable standaloneTable = new StandaloneTableClass();
standaloneTable.Table = srTable;
pTableCollection.AddStandaloneTable(standaloneTable);
ftrLayer.FeatureClass = xyEventSource as IFeatureClass;
ftrLayer.Name = "My Table";
map.AddLayer(ftrLayer);Right-clicking on the layer created as above and choosing Properties shows this for the source:
Data Type: XY Event Source
Location: C:\data\database.mdb
Feature Class: MyTable_Features
Feature Type: Simple
Geometry Type: Point
However, if you conduct the Display XY Data operation manually in ArcMap on a standalone table added to the TOC, the following shows for the source, and this is what I'm after:
Data Type: XY Event Source
Location: C:\data\database.mdb
Table: C:\data\database.mdb\MyTable
X Field: myX
Y Field: myY
Has Object-ID Field: Yes
What in the world am I doing wrong?
Thank you for any assistance!
Mike