Select/Loop through features, one at a time

7249
10
09-06-2011 03:54 PM
MikeLouwrens
Occasional Contributor III
I am wanting to create a tool where I can click a button and it will either select the first record of a specific featurelayer, or if there is already a feature selected it will unselect that feature and select the next one.

How do I tell it to select very first record (ie lowest objectid) in the featurelayer?  Or if there is already a feature selected, how do I tell it to select the next record?

I don't think this should be too hard, I've just come up blank when trying to figure it out this morning.
Really all I'm doing is:
If nothing selected, select Row 1
else if something selected, select Row(selected)+1

I'm trying this currently in VBA, but will be moving to .Net once I've got something working.

Thanks,
Mike.
0 Kudos
10 Replies
SusanJones
Occasional Contributor II
Try this:

i am not sure if I understand your logic (because features are independant of one another).

'get a reference to the feature Layer pFeatureLayer

dim pFeatureSelection as IFeatureSelection = pFeatureLayer
dim pSelectionSet as ISelectionSet =  pFeatureSelection.SelectionSet
dim pFeatureCursor as IFeatureCursor
pSelectionSet.Search Nothing, true, pFeatureCursor
set pFeature as IFeature = pFeatureCursor.NextFeature

'loop
Do While not pFeature is Nothing

  'do Something

'next Feature
set pFeature as IFeature = pFeatureCursor.NextFeature  

Loop

Susan


--
Susan Jones
GIS Consultant
Spatial Logic Ltd
Auckland, NEW ZEALAND

Email: sjones@spatiallogic.co.nz
http://www.spatiallogic.co.nz
0 Kudos