Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to implement a custom selection tool in ArcMap 9.3.1 that is functionally similar to the default ArcMap selection tool with "Adding to current selection" enabled. ie. the user can click to incrementally select individual features one by one, while adding on to previously selected features. When the user clicks on an already selected feature, that feature should be unselected.

How should I go about replicating and implementing this behavior for my custom tool? There are some selection-related code snippets lying around, but nothing really comes close. I was able to perform single selections by calling SelectByShape(geom, null, true), where geom = a small area around the clicked point. To support multiple selections at various locations, how then do I keep the previously selected features still selected as I select a new one, since SelectByShape(geom, null, true) only selects a single feature each time it's called.

Clearly, I will need another approach, which probably involves me keeping a growing list of currently selected features, but I am not sure if there is a more straightforward solution. Has anyone attempted this before?

Many thanks!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I believe in your scenario, you can keep on using SelectByShape method within the following sequence:

  1. Access IMxApplication.SelectionEnvironment, save the value of ISelectionEnvironment.CombinationMethod to a temporary variable.

  2. Set ISelectionEnvironment.CombinationMethod to esriSelectionResultEnum.esriSelectionResultXOR. This will ensure proper handling of already selected features, which will be unselected when part of the new selection.

  3. Pass the application's selection environment to SelectByShape, calling the method as you already do. SelectByShape will use the selection environment selection method you set previously. Consider using justOne=false to support adding/removing multiple features at a time.

  4. Restore the selection environment's combination method to that saved aside in the first step.

share|improve this answer
    
Thanks Petr! I followed your steps and got it to work perfectly! –  kentoh Oct 3 '12 at 6:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.