2

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?

david_p
1,8031 gold badge20 silver badges34 bronze badges
asked Jan 30, 2015 at 4:06

1 Answer 1

1

I would be surprised if you could alter the interface of that window as that is a core part of the desktop editing environment. I've not tried it but you may be able to capture the "on feature change" event, pass your ID value into your sub ID field but if that updates that windows I have no idea?

EDIT:

I have done something similar in the past, the Feature Class was a file geodatabase feature class and I had set the default value to be -1 for an ID field called HERID. So when a new feature is created it is automatically given a -1 value.

Below is my on Feature Create procedure. I've removed most of the code for clarity but see how I search for a feature where the HERID = -1. I then have a handle on the feature just created and I too am using store to commit the changes to the fields.

Private Sub m_EditEvents_OnCreateFeature(obj As ESRI.ArcGIS.Geodatabase.IObject) Handles m_EditEvents.OnCreateFeature
 ' Declare objects
 Dim d As Date
 Dim pEditLayers As IEditLayers
 Dim pFeatureLayer As IFeatureLayer
 Dim pFeatureCursor As IFeatureCursor
 Dim pFeature As IFeature
 Dim pQueryFilter As IQueryFilter
 Try
 ' Set objects
 d = Date.Today
 pEditLayers = m_Editor
 pFeatureLayer = pEditLayers.CurrentLayer
 pQueryFilter = New QueryFilterClass
 pQueryFilter.WhereClause = "HERID = -1"
 pFeatureCursor = pFeatureLayer.Search(pQueryFilter, False)
 pFeature = pFeatureCursor.NextFeature
 If Not pFeature Is Nothing Then
 ' Must be a new feature created
 With pFeature
 .Value(.Fields.FindField("HERID")) = HERID
 .Value(.Fields.FindField("IsPrimary")) = 1
 .Value(.Fields.FindField("FCD")) = d.ToShortDateString
 .Value(.Fields.FindField("FLMD")) = d.ToShortDateString
 .Store()
 End With
 End If
 Catch ex As Exception
 MsgBox(ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error in m_EditEvents_OnCreateFeature")
 Finally
 ' Clean up
 pEditLayers = Nothing
 pFeatureLayer = Nothing
 pFeatureCursor = Nothing
 pFeature = Nothing
 pQueryFilter = Nothing
 End Try
End Sub
answered Jan 30, 2015 at 8:51
5
  • Hi Hornbydd, are you talking about feature.store? I tried it but it not work. I have updated my question with the related code. Kindly advise me, thank you very much! Commented Feb 2, 2015 at 5:49
  • I'm not sure that is the best way of doing it. I would use the IEditEvents Interface and its OnCreateFeature method which returns the actual row which you could update. There is some sample code on that page. Commented Feb 2, 2015 at 16:34
  • Hi Hornbydd, actually I am using OnCreateFeature to popup a window to ask user to fill in the attribute values of the new created feature, but failed to update the value in attribute table. You suggest use other method instead of feature.store? sorry I am stupid stuck here. Commented Feb 3, 2015 at 4:03
  • I have edited my answer. Commented Feb 3, 2015 at 11:30
  • Hi Hornbydd, thanks a lot for your example, tested and worked properly. Commented Feb 4, 2015 at 2:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.