数据编辑做过很多次,没怎么出现问题,今天出现了问题,浪费了大半天,记录一下。
问题:修改Featrue的属性,修改后停止编辑,但是没有提示是否保存修改
原因:在编辑数据的时候没有加StartEditOperation方法。
解决办法:在修改数据的时候加上StartEditOperation和StopEditOperation方法
代码如下:
1、打开工作空间和开始编辑
''' <summary> ''' 开始编辑VB ''' </summary> ''' <remarks></remarks> Public Function StartEdit() As Boolean If IsNothing(pWorkspaceEdit) Then Dim pWorkspaceFactory As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory Dim dataset As IDataset = pPointFeatureLayer.FeatureClass Dim workspace As IWorkspace = pWorkspaceFactory.OpenFromFile(dataset.Workspace.PathName, 0) pWorkspaceEdit = workspace End If pWorkspaceEdit.StartEditing(True) End Function
//开始编辑C# if(pWorkspaceEdit==null) { IWorkspaceFactory pWorkspaceFactory =new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory(); IDataset dataset =pFeatureLayer.FeatureClass as IDataset; IWorkspace workspace = pWorkspaceFactory.OpenFromFile(dataset.Workspace.PathName, 0); pWorkspaceEdit = workspace as IWorkspaceEdit; pWorkspaceEdit.StartEditing(true); }
2、开始操作和停止操作
Public Function StartOperation() As Boolean pWorkspaceEdit.StartEditOperation() Return True End Function Public Function StopOperation() As Boolean pWorkspaceEdit.StopEditOperation() Return True End Function
3、保存编辑
''' <summary> ''' 保存编辑 ''' </summary> ''' <remarks></remarks> Public Function StopEdit() As Boolean 'pWorkspaceEdit.IsBeingEdited() Dim bSave As Boolean If Not HasEdits() Then bSave = False Else Dim r As System.Windows.Forms.DialogResult r = MessageDialog.Show("是否保存编辑?", "提示", Windows.Forms.MessageBoxButtons.YesNoCancel) Select Case r Case Windows.Forms.DialogResult.Yes bSave = True Case Windows.Forms.DialogResult.No bSave = False Case Windows.Forms.DialogResult.Cancel Return True End Select End If pWorkspaceEdit.StopEditing(bSave) Return True End Function Private Function HasEdits() As Boolean Dim bHasEdits As Boolean pWorkspaceEdit.HasEdits(bHasEdits) Return bHasEdits End Function
4、修改数据的地方
m_editor.StartOperation() Dim pFieldIndex As Integer = pTagFeature.Fields.FindField(e.ChangedItem.PropertyDescriptor.Name) pTagFeature.Value(pFieldIndex) = e.ChangedItem.Value pTagFeature.Store() m_editor.StopOperation()