ArcGIS基础代码(2)——Edit Attributes in ArcEngine

本文介绍了如何在ArcEngine中进行编辑属性的操作,包括`StartEditing`和`StopEditing`子程序,用于开始和结束编辑会话,并提示用户保存更改。此外,还提到了独立表格的编辑,强调了使用更新游标和存储更改的过程,但需要注意MDB表的限制,建议转换为GDB表。

1/if FeatureClass

      StartEditing:

      Public Sub StartEditing()
    Dim pWorkspaceEdit As IWorkspaceEdit
    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pFeatureLayer As IFeatureLayer
    Dim pDataset As IDataset

    On Error GoTo StartEditing_err

    ' Check edit conditions before allowing edit to start
    If g_SubAreaLayer Is Nothing Then
        MsgBox "ÇëÏÈÉèÖòéѯͼ²ã£¡"

        Exit Sub
    End If

   Set pFeatureLayer = g_SubAreaLayer


    Set pDataset = pFeatureLayer.FeatureClass
    If pDataset Is Nothing Then Exit Sub

    ' Start editing, making sure that undo/redo are enabled
    Set pWorkspaceEdit = pDataset.Workspace
    If Not pWorkspaceEdit.IsBeingEdited Then
        pWorkspaceEdit.StartEditing True
        pWorkspaceEdit.EnableUndoRedo
    End If

Exit Sub

StartEditing_err:
    MsgBox err.Description
End Sub

     FeatureCursor.NextFeature

    Feature.Store

    StopEditing

Public Sub StopEditing()
    Dim pFeatureLayer As IFeatureLayer
    Dim pDataset As IDataset
    Dim pWorkspaceEdit As IWorkspaceEdit
    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pAV As IActiveView

    Dim bHasEdits As Boolean
    Dim bSave As Boolean

    On Error GoTo StopEditing_err

    ' Check edit conditions before allowing edit to stop

    Set pFeatureLayer = g_SubAreaLayer
    Set pDataset = pFeatureLayer.FeatureClass
    If pDataset Is Nothing Then Exit Sub

    ' If the current document has been edited then prompt the user to save changes
    Set pWorkspaceEdit = pDataset.Workspace
    If pWorkspaceEdit.IsBeingEdited Then
        pWorkspaceEdit.HasEdits bHasEdits
        If bHasEdits = True Then
            If vbYes = MsgBox("Do you want to save your edits?", vbQuestion + vbYesNoCancel, "Question Dialog") Then
                bSave = True
            End If
        End If
        pWorkspaceEdit.StopEditing bSave
    End If

    Set pDoc = m_App.Document
   
    Set pAV = pDoc.ActiveView
    pAV.Refresh

Exit Sub

StopEditing_err:
    MsgBox err.Description
End Sub

 

2/StandaloneTable

不需要StartEditing

只需得到Update Cursor

然后IRow.Store

  Dim pTabCollection As IStandaloneTableCollection
  Dim pStTable As IStandaloneTable
  Set pTabCollection = pMap

Set pStTable = pTabCollection.StandaloneTable(0)
Set pCS = pStTable.Table.Update(Nothing, True)

但要注意普通MDB Table不能编辑

应该先转成GDB Table

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值