Trouble looping through a selection set where feature type is polyline which is part of a topology class.

588
1
08-31-2017 05:26 AM
LawrenceHartpence
New Contributor

Hello.

I have code that loops through selected features and updates an attribute for those features.  The code throws an error at runtime when the featureclass is a polyline type which participates in a topology class.  The error seems to happen at iSelectionset.Update.  Below is the entire function.  Any ideas would be appreciated.

Private Sub txtRFrom_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtRFrom.KeyPress
If Asc(e.KeyChar) = 13 Or Asc(e.KeyChar) = 9 Then
If cmbLayer.SelectedIndex = -1 Then
MsgBox("Please Select an Edit Layer!!")
Exit Sub
End If

Dim intValue As Integer

If Not Integer.TryParse(txtRFrom.Text, intValue) Then
txtRTo.Focus()
Exit Sub
End If

Dim pfLayer As IFeatureLayer
pfLayer = FindLayerByName(cmbLayer.SelectedItem)

Dim pfClass As IFeatureClass
pfClass = pfLayer.FeatureClass


Dim pfeatsel As IFeatureSelection
pfeatsel = pfLayer


Dim pSelectionSet As ISelectionSet2
pSelectionSet = pfeatsel.SelectionSet

If pSelectionSet.Count = 0 Then
MsgBox("No features selected!!")
Exit Sub
End If

Dim pFeatureCursor As IFeatureCursor
pFeatureCursor = Nothing

Dim pFeature As IFeature

'update the selectionset setting the IQueryFilter object to Nothing

pSelectionSet.Update(Nothing, False, pFeatureCursor)

pFeature = pFeatureCursor.NextFeature

Do Until pFeature Is Nothing


pFeature.Value(pFeature.Fields.FindField("RFromAddr")) = txtRFrom.Text

pFeatureCursor.UpdateFeature(pFeature)
pFeature = pFeatureCursor.NextFeature

txtRTo.Focus()
Loop
End If

End Sub

0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor

If you want people to help I suggest you edit your question and ensure formatting of code is on as it makes it easier to read. Have a look here if you do not know how to do this.

If you read the API help for the Update method, it states at the bottom:

All edits to features that participate in a Topology or Geometric Network must be bracketed within an edit operation.

Your code does not indicate if an Edit operation has been started so I'm guessing that is the issue.

0 Kudos