I want to be able to select a single feature based upon where user clicks on the screen. How can I do this using ArcObjects? Thanks!
Hi, using vb, here is a main function which selects a feature (only one) from a selected layer.
Public Function Form_Initialize(ByVal m_application As ESRI.ArcGIS.Framework.IApplication) As Boolean Try pMxDoc = m_application.Document Dim pMap As IMap pMap = pMxDoc.FocusMap
' Get the selected layer Dim pLayer As IGeoFeatureLayer pLayer = pMxDoc.SelectedLayer
' Make sure a layer was selected If pLayer Is Nothing Then MsgBox("You must select a Layer to Attribute") Close() Exit Function End If
' Get the feature class to get the correct ' oid field name for the data type (oid,fid,objectid) 'Dim pFc As IFeatureClass 'this is declared up top Dim strOIDName As String pFc = pLayer.FeatureClass strOIDName = pFc.OIDFieldName
' Get the selected features from the layer Dim pFSel As IFeatureSelection pFSel = pLayer Dim pSelSet As ISelectionSet pSelSet = pFSel.SelectionSet 'Dim pFCur As IFeatureCursor 'declared up top pSelSet.Search(Nothing, False, pFCur)
' ensure only 1 feature selected If Not pSelSet.Count = 1 Then MsgBox("You must select one and only one feature.") Close() 'Exit Function Else 'setup the combo boxes fillComboBoxes() pFeat = pFCur.NextFeature loadSegment(pFeat)
End If
Catch ex As Exception MsgBox("Exception in Form_Initialize") System.Windows.Forms.MessageBox.Show(ex, "Initialize") Return False End Try End Function