Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Im running arcmap 9.1. i have the code that lists feature classes in a list box from the SDE. The users select from one list box and adds it to another list box. How do i get it to show the layer name not feature class name?? How can i make sure it keeps the same symbology as it has in the SDE? When i run this code it adds it as new layer with new symbology. I do not have the password for the SDE so it is extracting the feature classes by using the parent workspace of a selected layer in the Layers list.

Public Sub AddSDECoverageLayer()


Dim pFWorkspace As IFeatureWorkspace
Dim pFeatureWorkspace As IFeatureWorkspace

Dim pFLayer As IFeatureLayer

Dim pMxDoc As IMxDocument
Dim pMap As IMap

Dim pDataSet As IDataset
Dim pFeatureLayer As IFeatureLayer
Dim pFeatureClassName As IFeatureClassName
Dim pUnknown As IUnknown
Dim pWorkSpace As IWorkspace
Dim pParentWorkSpaceName As IWorkspaceName



 ' Get the selected layer
 Set pMxDoc = ThisDocument

 Set pUnknown = pMxDoc.SelectedLayer 
  If Not TypeOf pUnknown Is IFeatureLayer Then
   Exit Sub
 End If
 Set pFeatureLayer = pUnknown



 ' Make sure the layer is from SDE and get the parent workspace
   Set pDataSet = pFeatureLayer.FeatureClass
   Set pFeatureClassName = pDataSet.FullName
   Set pFWorkspace = pDataSet.Workspace
  ' If Not pWorkSpace.Type = esriRemoteDatabaseWorkspace Then
  '  MsgBox "Not an SDE feature class"
  '  Exit Sub
  'End If
  'Set pDataSet = pWorkSpace
  'Set pParentWorkSpaceName = pDataSet.FullName


  Dim intX As Integer

 'Add each FeatureLayer to the map document
 'Create New Layer
 ‘ How do I keep the symbology the same as whats on the SDE?

 For intX = 0 To ListBox2.ListCount - 1

     Set pFLayer = New FeatureLayer
        Set pFLayer.FeatureClass = pFWorkspace.OpenFeatureClass(ListBox2.List(intX))

        pFLayer.Name = pFLayer.FeatureClass.AliasName
        Set pMxDoc = ThisDocument
        Set pMap = pMxDoc.FocusMap

        pMap.AddLayer pFLayer
Next


pMxDoc.ActiveView.Refresh



End Sub

The code below gets the feature class name and adds them to listbox.

Private Sub CommandButton4_Click()

Dim pDoc As IMxDocument
Set pDoc = ThisDocument

Dim pUnknown As IUnknown

Dim pFeatureLayer As IFeatureLayer
Dim pMxDoc As IMxDocument
Dim pSdeWorkspaceFactory As IWorkspaceFactory

Dim pWorkSpace As IWorkspace
Dim pParentWorkSpaceName As IWorkspaceName
Dim pDataSet As IDataset
Dim pFeatureClassName As IFeatureClassName


Dim pFWorkspace As IFeatureWorkspace

 'Get the selected layer
  Set pMxDoc = ThisDocument
  Set pUnknown = pMxDoc.SelectedLayer 
    If Not TypeOf pUnknown Is IFeatureLayer Then
    Exit Sub
   End If
   Set pFeatureLayer = pUnknown


  ' Make sure the layer is from SDE and get the parent workspace
  Set pDataSet = pFeatureLayer.FeatureClass
  Set pFeatureClassName = pDataSet.FullName
 'Set pFWorkspace = pDataSet.Workspace
  Set pWorkSpace = pFWorkspace
    If Not pWorkSpace.Type = esriRemoteDatabaseWorkspace Then
    MsgBox "Not an SDE feature class"
  Exit Sub
  End If
Set pDataSet = pWorkSpace
Set pParentWorkSpaceName = pDataSet.FullName

Dim pEnumDSName As IEnumDatasetName
Dim pSdeDSName As IDatasetName

Set pEnumDSName = pWorkSpace.DatasetNames(esriDTFeatureClass)
Set pSdeDSName = pEnumDSName.Next
Set pFWorkspace = pWorkSpace

how do I get it to show layer name and not feature class name?

   While Not pSdeDSName Is Nothing
    ListBox1.AddItem pSdeDSName.Name
  Set pSdeDSName = pEnumDSName.Next

Wend



End Sub
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.