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
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.
-
may be a better option to only update
bSelected
in response to events inISelectionEvents Interface
so that you're only checking the selection count when it actually changes, and not every time ArcGIS fires the update eventtomfumb– tomfumb2015年02月11日 19:39:01 +00:00Commented Feb 11, 2015 at 19:39
Explore related questions
See similar questions with these tags.