Select to view content in your preferred language

Add layers to ArcMap from VB.NET form

3306
3
04-19-2010 12:17 AM
AdrianWelsh
MVP Honored Contributor
Hi. I have a VB.NET form that I'm using as a standalone application.  On this form, a user can navigate to different files and the file path is stored in a list box.  I want the user to be able to click on a file (or files) from the listbox and have those files (which are Feature Layers) get put into the table of contents of an existing ArcMap project.

Is there any kind of "load layer from string" command out there? Or anything like that?  Please let me know!

Thanks!
0 Kudos
3 Replies
AdrianWelsh
MVP Honored Contributor
a hopeful bump for the new week...
0 Kudos
BelindaJerger
Emerging Contributor
I'm not sure if you've had any luck with your issue.  Unfortunately, there is no basic "open this layer" command.  I'll try to outline some code I have that someone else created. If it seems a bit disorganized and choppy I apologize, I'm adapting it for your use from code we use everyday to add annotation layers to a map.  So I'm hoping I can at least get you started on the right track.

'First, need to have an IFeatureWorkspace.  Set your a new feature workspace from your existing workspace
pFeatureWorkspace = pWorkspace

'Create a new feature layer object
Dim pFlayer As New ESRI.ArcGIS.Carto.FeatureLayer

'Set the new object feature class to the open feature class
pFlayer.FeatureClass = pFWkSpc.OpenFeatureClass("MyLayerName")

'You can't add a feature class to an IMap object, it has to be a an FDOGraphicsLayer object so...

'Create a new feature dataset object
Dim pFeatureDataset As ESRI.ArcGIS.Geodatabase.IFeatureDataset

'set the object to the featurelayer dataset 
pFeatureDataset = pFlayer.FeatureClass.FeatureDataset

'create new fdographicslayer and fdographicslayerfactory objects
Dim pFDOGrLayer As ESRI.ArcGIS.Carto.IFDOGraphicsLayer
Dim pFDOGLFactory As ESRI.ArcGIS.Carto.IFDOGraphicsLayerFactory

'The factory must be 'new'
pFDOGLFactory = New ESRI.ArcGIS.Carto.FDOGraphicsLayerFactory

'Then set the layer to the factory opengraphicslayer call with the feature workspace, feature dataset,
and string name of your layer.
pFDOGrLayer = pFDOGLFactory.OpenGraphicsLayer(pFeatureWorkspace, pFeatureDataset, "string name of layer")

'Finally add the fdographicslayer to the map.  
pMap.AddLayer(pFDOGrLayer)


Hopefully this works.  I haven't tested it, but like I said we use a similar process to add annotation layers so I'm ever so hopeful.  Good luck and if this doesn't work for you maybe it can at least set you in the right direction with libraries and such.
0 Kudos
JohnHauck
Frequent Contributor
If your question is oriented around how to access a feature class or feature layer with its path as a string then you can use methods such as IGPUtilities2::OpenFeatureClassFromString or IGPUtilities2::OpenFeatureLayerFromString. However, if it's oriented around how to add data from a standalone form that's not directly associated with a running ArcGIS application then you will have more work to do. Please post again with additional information if necessary.
0 Kudos