Select to view content in your preferred language

Remove Layers

434
1
06-13-2010 02:55 AM
NehayaArabeiat
Emerging Contributor
Hi,

I want to add and delete layers when select and unselect comboboxes, it add layers correctly but when unselect the combobox to delete the layer it doesn't do anything, here is my code:

Private Sub DistChkBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DistChkBox.CheckedChanged
        If DistChkBox.Checked = True Then
            AddLayers(Distclass, "???????? ", objc.FeatureLayerDist)
        Else
            AxPageLayoutControl1.ActiveView.FocusMap.DeleteLayer(objc.FeatureLayerDist)
        End If

    End Sub



    Private Sub SubDistChkBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubDistChkBox.CheckedChanged

        If SubDistChkBox.Checked = True Then
            AddLayers(SubDistclass, "??????? ", objc.FeatureLayerSubDist)
        Else
            AxPageLayoutControl1.ActiveView.FocusMap.DeleteLayer(objc.FeatureLayerSubDist)
        End If


    End Sub




Public Sub AddLayers(ByVal layersclass As FeatureClass, ByVal classes As String, ByVal pfeaturelayerd As IFeatureLayer)

        Dim pfeaturelayer As IFeatureLayer
        pfeaturelayer = New FeatureLayer
        pfeaturelayer.FeatureClass = layersclass
        pfeaturelayer.Name = classes & " " & objc.govlista
        pfeaturelayer.ShowTips = True
        AxPageLayoutControl1.ActiveView.FocusMap.AddLayer(pfeaturelayer)
        pfeaturelayerd = pfeaturelayer
      
        AxPageLayoutControl1.Refresh()

    End Sub
0 Kudos
1 Reply
RuchiraWelikala
Regular Contributor
Try this out.

It's a basic for loop that goes through your mapcontrol and deletes the layer if the match condition is met.
It worked for me when I tested it.
if it doesn't work.  Try casting AxMapControl1 to the IMap interface.
Best of luck!

        For i = 0 To AxMapControl1.ActiveView.FocusMap.LayerCount
            If AxMapControl1.ActiveView.FocusMap.Layer(i).Name = "Name of Your Layer from listbox or combobox" Then
                AxMapControl1.ActiveView.FocusMap.DeleteLayer(AxMapControl1.ActiveView.FocusMap.Layer(i))
            End If
        Next
0 Kudos