Update attributes for selected (edit mode)

1361
13
Jump to solution
06-22-2012 08:26 AM
DaveCouture
New Contributor III
I'm trying to build a form that would assign a value to a field, for the selected features, during an edit session.  The user would create a new feature (in Edit mode) and the form would fill the attribute table. If the user is not in edit mode, the table won't be updated.

I'm kinda stuck there (vb.NET):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         Dim pMxDoc As IMxDocument         Dim pLayer As ILayer         Dim pFLayer As IFeatureLayer         Dim pFeatClass As IFeatureClass         Dim pMap As IMap         Dim pCursor As ICursor         Dim pFSel As IFeatureSelection         Dim pSelSet As ISelectionSet2          pMxDoc = My.ArcMap.Document         pMap = pMxDoc.FocusMap         pLayer = pMxDoc.SelectedLayer         pFLayer = pLayer         pFeatClass = pFLayer.FeatureClass         pCursor = pFeatClass.Update(Nothing, True)         pFSel = pLayer         pSelSet = pFSel.SelectionSet         pSelSet.Update(Nothing, False, pCursor)          Do Until pFSel Is Nothing             pFSel.Value(pFSel.Fields.FindField("Source")) = "Coordinate"             pFSel = pFSel.Next         Loop  End Sub
0 Kudos
13 Replies
KenBuja
MVP Esteemed Contributor
I notice that you don't have the line

Inherits ESRI.ArcGIS.Desktop.AddIns.Extension

in your code. This was included in your previous code attachment

Also, you'll need to add the line

pFeature = pEnumFeature.Next

before you start the Do Loop.
0 Kudos
DaveCouture
New Contributor III
Thanks Ken, I got it to work. 


The problem was with this line:
Dim pEditor As ESRI.ArcGIS.Editor.IEditor
pEditor = m_application.FindExtensionByName("esriEditor.Editor")


I ended up using:
Dim pEditor As ESRI.ArcGIS.Editor.IEditor
pEditor = My.ArcMap.Application.FindExtensionByName("esriEditor.Editor")




The whole code:
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Framework
Imports System.Windows.Forms
Imports ESRI.ArcGIS.Editor

Public Class EaseRowEditorForm
    Inherits System.Windows.Forms.Form


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim pEnumFeature As ESRI.ArcGIS.Geodatabase.IEnumFeature
        Dim pFeature As ESRI.ArcGIS.Geodatabase.IFeature
        Dim pEditor As ESRI.ArcGIS.Editor.IEditor

        pEditor = My.ArcMap.Application.FindExtensionByName("esriEditor.Editor")
        pEnumFeature = pEditor.EditSelection
        pEnumFeature.Reset()
        pFeature = pEnumFeature.Next

        Do Until pFeature Is Nothing
            pFeature.Value(pFeature.Fields.FindField("Source")) = "Coordinates"
            pFeature.Store()
            pFeature = pEnumFeature.Next
        Loop
    End Sub

End Class
0 Kudos
KenBuja
MVP Esteemed Contributor
I'm glad that worked out. It's curious that you can use My.ArcMap but not My.ArcMap.Editor
0 Kudos
DaveCouture
New Contributor III
Forgot to add:  pEditor.StartOperation() and pEditor.StopOperation("UpdateFields")

       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim pEnumFeature As ESRI.ArcGIS.Geodatabase.IEnumFeature
        Dim pFeature As ESRI.ArcGIS.Geodatabase.IFeature
        Dim pEditor As ESRI.ArcGIS.Editor.IEditor

        pEditor = My.ArcMap.Application.FindExtensionByName("esriEditor.Editor")
        pEnumFeature = pEditor.EditSelection
        pEnumFeature.Reset()
        pFeature = pEnumFeature.Next
        pEditor.StartOperation()

        Do Until pFeature Is Nothing
            pFeature.Value(pFeature.Fields.FindField("Source")) = "Coordinates"
            pFeature.Store()
            pFeature = pEnumFeature.Next
        Loop

        pEditor.StopOperation("UpdateFields")

    End Sub
0 Kudos