<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Adding XY event source programatically in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570468#M15377</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can add a table as an XYEventSource from an Access database, with the following code.&amp;nbsp; This works.&amp;nbsp; My problem is described after the code block.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
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);
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&amp;nbsp; 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Right-clicking on the layer created as above and choosing Properties shows this for the source:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Data Type: XY Event Source &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Location: C:\data\database.mdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Feature Class: MyTable_Features&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Feature Type: Simple&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Geometry Type: Point&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Data Type: XY Event Source&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Location: C:\data\database.mdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Table: C:\data\database.mdb\MyTable&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;X Field: myX&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Y Field: myY&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Has Object-ID Field: Yes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What in the world am I doing wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for any assistance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Apr 2013 16:17:40 GMT</pubDate>
    <dc:creator>MikeDuppong</dc:creator>
    <dc:date>2013-04-03T16:17:40Z</dc:date>
    <item>
      <title>Adding XY event source programatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570468#M15377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can add a table as an XYEventSource from an Access database, with the following code.&amp;nbsp; This works.&amp;nbsp; My problem is described after the code block.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
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);
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&amp;nbsp; 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Right-clicking on the layer created as above and choosing Properties shows this for the source:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Data Type: XY Event Source &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Location: C:\data\database.mdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Feature Class: MyTable_Features&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Feature Type: Simple&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Geometry Type: Point&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Data Type: XY Event Source&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Location: C:\data\database.mdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Table: C:\data\database.mdb\MyTable&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;X Field: myX&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Y Field: myY&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Has Object-ID Field: Yes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What in the world am I doing wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for any assistance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 16:17:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570468#M15377</guid>
      <dc:creator>MikeDuppong</dc:creator>
      <dc:date>2013-04-03T16:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding XY event source programatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570469#M15378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
map.AddLayer(xyEventSource);
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wouldn't this work?&amp;nbsp; XYEventSource implements ITable, which you can pass to your map.AddLayer() method.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:33:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570469#M15378</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2021-12-12T00:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Adding XY event source programatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570470#M15379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Negative.&amp;nbsp; AddLayer() requires an ILayer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 19:06:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570470#M15379</guid>
      <dc:creator>MikeDuppong</dc:creator>
      <dc:date>2013-04-03T19:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding XY event source programatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570471#M15380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;doh.&amp;nbsp; sorry about that...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I meant map.addTable()&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 19:18:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570471#M15380</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2013-04-03T19:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Adding XY event source programatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570472#M15381</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the response.&amp;nbsp; However, I don't see an AddTable() method for the IMap interface.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 19:27:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570472#M15381</guid>
      <dc:creator>MikeDuppong</dc:creator>
      <dc:date>2013-04-03T19:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Adding XY event source programatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570473#M15382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;IMap is an Interface for concrete classes: Globe, Map, Scene.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IMap would not have an addTable() method because Globe and Scene would need to implement that contract.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How did you create your IMap variable?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 20:23:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570473#M15382</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2013-04-03T20:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Adding XY event source programatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570474#M15383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;IMxDocument pMxDoc = m_app.Document as IMxDocument;
IMap map = pMxDoc.FocusMap;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;m_app is set within the OnCreate() method of the BaseCommand:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if((hook) is IMxApplication)
&amp;nbsp; m_app = (IApplication)hook;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:33:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570474#M15383</guid>
      <dc:creator>MikeDuppong</dc:creator>
      <dc:date>2021-12-12T00:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: Adding XY event source programatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570475#M15384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;pMxDoc.FocusMap&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;This returns an IMap reference.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to QI (or cast) to the Map class if you want to use addTable().&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 20:54:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570475#M15384</guid>
      <dc:creator>LeoDonahue</dc:creator>
      <dc:date>2013-04-03T20:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Adding XY event source programatically</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570476#M15385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;pMxDoc.FocusMap&lt;/PRE&gt;&lt;BR /&gt;This returns an IMap reference.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;You need to QI (or cast) to the Map class if you want to use addTable().&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for sticking with me, Lee.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I QI'd the IMap to an ITableCollection and used its AddTable() method.&amp;nbsp; This results in:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Data Type: Standalone Table&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Table Name: MyTable_Features&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Table Type: XY Event Source&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Location: C:\data\database.mdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Has Object-ID Field: Yes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Still not quite there.&amp;nbsp; Still shooting for:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Data Type: XY Event Source&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Location: C:\data\database.mdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Table: C:\data\database.mdb\MyTable&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;X Field: myX&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Y Field: myY&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Has Object-ID Field: Yes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I feel like I'm painfully close...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Apr 2013 13:04:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/adding-xy-event-source-programatically/m-p/570476#M15385</guid>
      <dc:creator>MikeDuppong</dc:creator>
      <dc:date>2013-04-04T13:04:21Z</dc:date>
    </item>
  </channel>
</rss>

