dimanche 1 février 2015

arcmap editor attribute window fill value programmatically


In my map I have a layer named PARCEL, when create new feature on this layer, the attribute window will open automatically. There are 2 attributes in this layer: PARCEL_ID and SUB_ID.


Since the PARCEL_ID is the left part of SUB_ID, I intend to display the PARCEL_ID value in SUB_ID field after user input the PARCEL_ID value, this is to minimize user key in wrong information.


Is there a way to do this without a customized editor tool?


enter image description here


I am using vb.net arcobjects 10.2.2.


EDIT1


The reason for use the attribute window in editor is when I tried to use update feature, it didn't work.


Actally my basic idea is after user create new feature:


(1) use max OBJECTID to identify the new created feature


(2) provided a window to ask user to input the PARCEL_ID and SUB_ID of the new created feature


(3) use feature.store to update the PARCEL_ID and SUB_ID values


But I failed to make it work. My code is like followings:



Private Sub GetMaxFID()
Try
Dim pMxDoc As IMxDocument, pFLayer As IFeatureLayer
Dim pCursor As ICursor
pMxDoc = My.ArcMap.Application.Document

Dim pMap As IMap
Dim pActiveView As IActiveView

pMap = pMxDoc.FocusMap
pActiveView = pMxDoc.FocusMap

Dim layerNum = GetIndexNumberFromLayerName(pActiveView, My.Settings.ParcelLayer)
pFLayer = pMxDoc.FocusMap.Layer(layerNum)
pCursor = pFLayer.Search(Nothing, False)

If TypeOf pCursor Is IFeatureCursor Then
Dim pData As IDataStatistics = New DataStatisticsClass
pData.Field = "OBJECTID"
pData.Cursor = pCursor
Dim pStatResults As IStatisticsResults = pData.Statistics
newOBJECTID = pStatResults.Maximum
End If

Catch ex As Exception
logger.Error(ex.ToString)
End Try
End Sub

Protected Overrides Sub OnClick()
Try
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pActiveView As IActiveView

pMxDoc = My.ArcMap.Application.Document
pMap = pMxDoc.FocusMap
pActiveView = pMxDoc.FocusMap

Dim layerNum = GetIndexNumberFromLayerName(pActiveView, My.Settings.ParcelLayer)
Dim pFLayer As IFeatureLayer

pFLayer = pMap.Layer(layerNum)

GetMaxFID()

Dim featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass = pFLayer.FeatureClass

If featureClass Is Nothing Then
Return
End If

Dim feature As IFeature = pFLayer.FeatureClass.GetFeature(newOBJECTID) ' is this line correct?

If feature Is Nothing Then
Return
End If

Dim objectIDFieldIndex As Integer = pFLayer.FeatureClass.FindField(newOBJECTID)

feature.Value(1) = "test123" 'This line I want to set the PARCEL_ID of the new created feature.
'is it correct to use .value(1) here? what should be the value of (1) in this line?
feature.Value(2) = "test123-12" 'This line I want to set the SUB_ID of the new created feature.
'is it correct to use .value(2) here? what should be the value of (1) in this line?

feature.Store()

'MsgBox("update finished")

Catch ex As Exception
logger.Error(ex.ToString)
End Try
End Sub


I believe there is something wrong with my code, how can I make it work? thanks.





Aucun commentaire:

Enregistrer un commentaire