1

The solution may be very simple, but I haven't made it work.

I want to enable a data view context menu item only if a feature (in polyline layer) is selected, all other places the item should in grey. May I say what I need to do is check whether a feature is selected? I searched for this but don't find a proper solution. Or any other concerns?

I am using ArcObjects 10.2.2 and VB.NET.

1 Answer 1

1

If you're making an ArcGIS Add-In (rather than the old extension format), then I believe you can enable / disable buttons or menu items inside your button class like this:

Protected Overrides Sub OnUpdate()
    Enabled = bSelected
End Sub

Where bSelected is your boolean indicating whether or not your feature is selected. You can check if a feature in a particular featurelayer is selected like this:

Dim pFeatureSelection As IFeatureSelection = pLayer
If pFeatureSelection.SelectionSet.Count = 0 Then
   bSelected = False
Else
   bSelected = True
End If

Or you could put them together to cut down on code. Try this:

Protected Overrides Sub OnUpdate()
   Dim pFeatureSelection As IFeatureSelection = pLayer
   If pFeatureSelection.SelectionSet.Count = 0 Then
      Enabled = False
   Else
      Enabled= True
   End If 
End Sub

EDIT: I've just realised you said context-menu, which I assume means a right click menu? In which case I'm not sure as I've never used context menus in ArcMap.

1
  • may be a better option to only update bSelected in response to events in ISelectionEvents Interface so that you're only checking the selection count when it actually changes, and not every time ArcGIS fires the update event Commented Feb 11, 2015 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.