I am relatively new at creating tools with ArcObjects and I am having trouble finding a layer based on the layer's source name by looping through all layers. I've seen here that it is possible, but I am unable to get it to work. Am I missing something simple or is there another approach that I should be taking? I see here it is possible to enumerate layers and loop through them, but I am still left trying to determine the source name of a layer. My example below is looking for a layer whose source is a feature class named buildings. If it helps, the dataset variable has a value of "Nothing" when I use a MessageBox to print the value of dataset.Name at each iteration.
'--other code to get editor, set up other variables, and start edit operation Dim findName As String = "buildings" Dim isLayerFound As Boolean = False Dim map as IMap = m_Editor.Map Dim subfield as Integer = 'some subfield integer '--Check For Point Layer In Editing If Not map Is Nothing Then '--Loop through all of the map layers to find the desired one For i = 0 To map.LayerCount - 1 Dim currentLayer As ILayer = map.Layer(i) Dim dataset As IDataset = CType(currentLayer, IDataset) If dataset.Name = findName Then isLayerFound = True '--Make sure layer is editable If m_editLayers.IsEditable(currentLayer) Then '--Set layer for editing m_editLayers.SetCurrentLayer(currentLayer, subfield) Exit For Else m_Editor.AbortOperation() MessageBox.Show("Layer " + findName + " is not editable. Operation aborted") Exit Sub End If End If Next i If isLayerFound = False Then m_Editor.AbortOperation() MessageBox.Show("Layer " + findName + " could not be found. Operation aborted") Exit Sub End If End If