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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 1, 2014 at 8:20

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.

answered Aug 1, 2014 at 8:30
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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.