2

I collect a set of OIDs into an OID array (long), this happens in a loop and if i find an OID i want to add to the array, I REDIM PRESERVE to expand the array.

iOIDListCount = iOIDListCount + 1
ReDim Preserve iOIDList(iOIDListCount)
iOIDList(iOIDListCount - 1) = pRow.OID
Debug.Print(iOIDList(iOIDListCount - 1))

Once I use this array to make my selelction via iFeatureSelection.SelectionSet.AddList there is no error but a the resulting selection is completely wrong. Instead of getting an expected 89 records the attribute table is reporting 40 is selected but only about 10 records is physically selected on screen and in the attribute table (see figure 1)

NOT WORKING CORRECTLY:

pFeatureSelection.SelectionSet.AddList(iOIDListCount, iOIDList(0))

However when I use a For Next loop instead and add the OID's individually, I get exactly what I expect: 89 records. (see figure 2)

WORKS FINE:

    For i = 0 To iOIDListCount - 1
        pFeatureSelection.SelectionSet.Add(iOIDList(i))
    Next i

Figure 1 - Incorrect selection result when using AddList approach enter image description here

Figure 2 - COrrect selection result when using Add (individually in a loop) approach enter image description here

  • I've not used addlist before, normally I would use ISelectionSet.Combine with esriSetOperation.esriSetUnion. First I would create a selection set with the ones I want to add, get the existing selection set, combine then cast the selection set to the FeatureSelection. The help doc help.arcgis.com/EN/sdk/10.0/ArcObjects_NET/componenthelp/… states "This method should not be called by .NET or Java applications. Instead, call IGeoDatabaseBridge2.AddList.", I think this is why. – Michael Stimson Sep 15 '15 at 22:03
5

It seems you can no longer trust the ISelectionSet.AddList, according to the help document:

This method should not be called by .NET or Java applications. Instead, call IGeoDatabaseBridge2.AddList.
[C#]
This method should not be used in .NET. Instead, use IGeoDatabaseBridge2.AddList.
[Visual Basic .NET]
This method should not be used in .NET. Instead, use IGeoDatabaseBridge2.AddList.

Which instructs to use IGeoDatabaseBridge2.AddList which I can't find any examples of, but it looks like it goes this way:

iOIDListCount = iOIDListCount + 1
ReDim Preserve iOIDList(iOIDListCount)
iOIDList(iOIDListCount - 1) = pRow.OID
Debug.Print(iOIDList(iOIDListCount - 1))
dim pGDBridge as IGeoDatabaseBridge2 = New GeoDatabaseHelperClass()
pGDBridge.AddList(pFeatureSelection.SelectionSet,iOIDList)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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