Trying to assign already selected features to ISelctionSet2

Discussion created by cgraham on Mar 19, 2013
Latest reply on Mar 20, 2013 by agray1
Good Afternoon,
I am trying to loop through a set of selected features for a specific layer.  The key issue I have is that the user will have already made a selection (with any of the out-of-the-box tools) when they click my button.

My code needs to make sure that key attributes are identical for all features selected in a certain layer, the rest of the selected features on the map are neither here nor there. 

All of the examples I find of how to use a count property on any of the objects that refer to a selection are solutions where the selection set is not made yet, and ISelectionSet is being used to 1) create the selection, then 2) return info about the selection.

Everything I've done in the past assumes that the user is using a custom tool to drive the selection process, and even then they are always selecting a single polygon.

So with all that background, here are the relatively straight forward questions:

  1. 1 Is it possible to assign features from one layer (that are already selected) to the selection set interface, not to make a selection, but to simply view properties about the selection

  2. 2  Assuming the answer to 1 is no; would I be able to setup some sort of query, or filter, or queryfilter to populate iSelectionSet2 with features from a specific layer that are currently selected? (esriSelectionResultAnd)

  3. 3 Assuming the answer to 2 is yes; would anyone have an example of how that hand off would look like? 

I could have sworn I've used something as straight forward as set pSelSet = OBJECT.SelectedFeatures in the past, but I can't seem to find it, so maybe I'm dreaming. 

While typing this I think I may have found a way to achieve #1 from above using the iFeatureSelection interface.  I'm going to post for future reference, and test it

    Dim pFSel As IFeatureSelection, pSelSet As ISelectionSet2, pFLayer As IFeatureLayer2

'(snipped a bunch of code that sets up pFLayer)

' *** Got this series of QI from an ESRI example, not sure how it will work out but will report back ***
    Set pFSel = pFLayer
    Set pSelSet = pFSel.SelectionSet
' *** End of ESRI Example technique ***

' What I really needed to do all along...
    iSelectedFeatureCount = pSelSet.Count
    If iSelectedFeatureCount < 1 Then 

I'll go test now, but if anyone has any ideas in the meantime please feel free to chime in.