Select to view content in your preferred language

How to set default value for primary key column in EditWiget  for new feature?

1266
9
10-22-2010 07:57 AM
XiujuZhou
Emerging Contributor
I have an ArcGIS API for silverlight 2 application. it uses feature service in arcgis server 10 to do online editing feature. I use EditWiget to add new feature by selecting feature type from Template Picker in the wiget. after draw a new feature, the attribute box popup for editing. I need to set default value for a primary Key column, not allow user type in the box. the default value is passed by others which is known in code.  How to do that? Please help. Thanks!
0 Kudos
9 Replies
JenniferNery
Esri Regular Contributor
The Attribute window that you see from the EditorWidget and TemplatePicker, is our FeatureDataForm.  How the form looks like depends on the FeatureLayer.  What you define as OutFields in your FeatureLayer, will be the fields displayed on the form.   If your FeatureLayer comes from a MapService, then everything will be read-only.  If your FeatureLayer comes from an editable FeatureService, then whatever type or settings the service had given its fields will also apply to the fields in the form.  In other words, to ensure that your primary key field is not editable, you have to make that setting in the feature service.

You can however, create your own attribute window and exclude the primary key field in your form so you can update this attribute with your default value.
0 Kudos
AliMirzabeigi
Emerging Contributor
In addition to Jennifer's comments you could alternatively do the following:
Do not include your primary key field in your layer OutFields property if the value for your primary key field could be populated through your code. This way the primary key field won't show up in the edit attributes form of the editor widget control and there won't be any risk of overwriting that value by the end users.
0 Kudos
XiujuZhou
Emerging Contributor
Thank you. If the way you mentioned happens in the Editor Widget,  how to populate the primary key column in code? when I click the submit button in the attribute box, then directly save attributes to SDE table without code. How to make code involve before save? What class object should be used for adding attributes to feature of layer?
if the way you mentioned happens in a customized attribute window, can customized attribute window still use the advanced features in the attribute window of widge? like dropdown combo box for subtype column, calendar for date column and data validation?


In addition to Jennifer's comments you could alternatively do the following:
Do not include your primary key field in your layer OutFields property if the value for your primary key field could be populated through your code. This way the primary key field won't show up in the edit attributes form of the editor widget control and there won't be any risk of overwriting that value by the end users.
0 Kudos
AliMirzabeigi
Emerging Contributor
You need to listen to the Graphics.CollectionChanged handler of your FeatureLayer and for each new item set your primary key attribute.
0 Kudos
XiujuZhou
Emerging Contributor
THank you Ali. Does the way apply for editorWiget? Could you let me know where to catch the event Graphics.CollectionChanged? at what point?

You need to listen to the Graphics.CollectionChanged handler of your FeatureLayer and for each new item set your primary key attribute.
0 Kudos
AliMirzabeigi
Emerging Contributor
Listen to EditCompleted event handler of your EditorWidget. You should check for Editor.EditAction.Add for the Action peoperty of the EditEventArgs.
0 Kudos
XiujuZhou
Emerging Contributor
good sigh. but I still have not get an entire picture. the piece of code I wrote below by follow your instruction:
private void Editor_EditCompleted(object sender, Editor.EditEventArgs e)
        {
             FeatureLayer myFeatureLayer = MyMap.Layers["dpcpoly"] as FeatureLayer;
          
            if (e.Action.Equals(Editor.EditAction.Add))
            {
            }
        }

Could you do me a bigger favor for further solution? Thank you!

Listen to EditCompleted event handler of your EditorWidget. You should check for Editor.EditAction.Add for the Action peoperty of the EditEventArgs.
0 Kudos
JenniferNery
Esri Regular Contributor
This is related thread: http://forums.arcgis.com/threads/9756-Undo-edits-of-the-EditorWidget (see post #9) to wire up to TemplatePicker's Editor.EditCompleted event.
0 Kudos
XiujuZhou
Emerging Contributor
THanks. I think Will check it.

This is related thread: http://forums.arcgis.com/threads/9756-Undo-edits-of-the-EditorWidget (see post #9) to wire up to TemplatePicker's Editor.EditCompleted event.
0 Kudos