<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Editing FeatureLayer and Validation in ArcGIS API for Silverlight Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333771#M8576</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Since you are dealing with multiple feature layers, I would advise that you set default values at the SDE level, i.e. for the required CodedValueDomain attributes associate a default value, say empty string as Code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Fields at the level of feature services are always considered as nullable data types and if you need to force them to be required an alternative approach would be extending current FeatureDataForm control and specifically look into the following method:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;private &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; HasChange(&lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 2; font-family: Consolas;"&gt;Control&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; control, &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;object&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; valueInGraphic, &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 2; font-family: Consolas;"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; type, &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;out &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; hasError)&lt;/SPAN&gt;
&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt;{&lt;/SPAN&gt;
&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt;}&lt;/SPAN&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 15:48:10 GMT</pubDate>
    <dc:creator>AliMirzabeigi</dc:creator>
    <dc:date>2021-12-11T15:48:10Z</dc:date>
    <item>
      <title>Editing FeatureLayer and Validation</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333766#M8571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've got a Silverlight 4 app that allows a user to edit one of 10 different Featurelayers withing the same FeatureService.&amp;nbsp; Basically, the user selects which layer to edit from a ComboBox.&amp;nbsp; I use that information to set up my Editor and a FeatureDataForm.&amp;nbsp; The user can add, remove, or edit these features, but what I want is Validation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Currently, there are non-nullable fields and default values on some of the fields on the FeatureLayers, but each one has a different set of fields.&amp;nbsp; What I want to happen is a validation error when a user does not enter a value for a non-nullable field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I have 2 questsions here.&amp;nbsp; 1) How to implement validation on a featuredataform and 2) How to make validation dynamic for the different featurelayers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Will&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Feb 2011 14:24:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333766#M8571</guid>
      <dc:creator>WilliamKimrey</dc:creator>
      <dc:date>2011-02-16T14:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Editing FeatureLayer and Validation</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333767#M8572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;FeatureDataForm and FeatureLayer performs validation based on the requirements of the feature service. Validation against type, domain and length.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need custom validation, you will need to write your own FeatureDataForm to ensure that certain fields are required and does not accept null values. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The source code for Toolkit is available in CodePlex &lt;/SPAN&gt;&lt;A href="http://esrisilverlight.codeplex.com/"&gt;http://esrisilverlight.codeplex.com/&lt;/A&gt;&lt;SPAN&gt;. If you need to take a look at what FeatureDataForm is currently doing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Feb 2011 18:36:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333767#M8572</guid>
      <dc:creator>JenniferNery</dc:creator>
      <dc:date>2011-02-16T18:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: Editing FeatureLayer and Validation</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333768#M8573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply.&amp;nbsp; Sadly, I'm not able to make my own FeatureDataForm at this time.&amp;nbsp; As I said, I have about 10 different feature layers that I'm editing and I don't want to have to make a different form for each one.&amp;nbsp; Especially since the required fields for each feature layer are different.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I can get around this issue if there is a way to determine which fields are not nullable.&amp;nbsp; Most of my feature layers contain domains and have a default values, but one field in particular does not and it's this field that is causing the problem.&amp;nbsp; It has a domain, but not a default value so when the feature service tries to add a feature, it fails because this field has a null value and the featureclass itself does not allow nulls for this field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This field that is causing a problem is not present in every feature class and some feature classes have different fields that cause the same problem.&amp;nbsp; So, if there's a way I can find out which fields do not allow nulls, I can check to see if they are null or not when I save and cancel the save if they are null.&amp;nbsp; I have yet to find a way to check for non nullable fields on a featurelayer.&amp;nbsp; Any ideas/suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Will&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Feb 2011 16:44:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333768#M8573</guid>
      <dc:creator>WilliamKimrey</dc:creator>
      <dc:date>2011-02-17T16:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Editing FeatureLayer and Validation</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333769#M8574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can have a lookup dictionary that holds a list of non-nullable fields per layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dictionary&amp;lt;string, List&amp;lt;Field&amp;gt;&amp;gt; lookup = new Dictionary&amp;lt;string, List&amp;lt;Field&amp;gt;&amp;gt;();&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For each layer's Initialized event:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
FeatureLayer l = sender as FeatureLayer
var nonNullableFields = new List&amp;lt;Field&amp;gt;();
foreach (var f in l.LayerInfo.Fields)
{
 if (!f.Nullable)
 nonNullableFields.Add(f);
}
lookup.Add(l.LayerInfo.Name, nonNullableFields);
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your FeatureLayer's AutoSave is False, you can explicitly call SaveEdits() in FeatureDataForm's EditEnded. This should allow you to perform validation check before saving the edits.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
void f_EditEnded(object sender, EventArgs e)
{
 FeatureDataForm f = sender as FeatureDataForm;
 FeatureLayer l = f.FeatureLayer;
 Graphic g = f.GraphicSource;
 var nonNullableFields = lookup[l.LayerInfo.Name];
 foreach (var item in g.Attributes)
 {
&amp;nbsp; if (ContainsField(item.Key, nonNullableFields) &amp;amp;&amp;amp; item.Value == null)
&amp;nbsp;&amp;nbsp; throw new Exception(string.Format("Field '{0}' cannot be null", item.Key));
 }
 l.SaveEdits();
}

private bool ContainsField(string name, List&amp;lt;Field&amp;gt; fields)
{
 foreach (var f in fields)
&amp;nbsp; if (name == f.Name) return true;
 return false;
}
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:48:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333769#M8574</guid>
      <dc:creator>JenniferNery</dc:creator>
      <dc:date>2021-12-11T15:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Editing FeatureLayer and Validation</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333770#M8575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jennifer,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the code.&amp;nbsp; My feature layer's AutoSave is set to false so i was checking at the EndSaveEdits event, but I hadn't figured out the initialization part of it yet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tested this code out and I'm sorry to say that it doesn't work.&amp;nbsp; I should work, but it's not returning a list of nonnullable fields.&amp;nbsp; I know for a fact that there area at least 5 nonnullable fields in one of my feature layers, but this code didn't catch any of them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm starting to think it's something wrong with the FeatureService itself.&amp;nbsp; The features are inside of a versioned (without move to base) dataset on an 9.3.1 sde database.&amp;nbsp;&amp;nbsp; However, the MXD was created in ArcDesktop 10 and published with ArcServer 10.&amp;nbsp; The application itself is Silverlight 4 using .NET Framework 4.&amp;nbsp; When you look at the fields in ArcDesktop, you see that they don't allow null values, so I can only conclude that something gets lost when I publish the service.&amp;nbsp; Any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Will&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Will&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Feb 2011 17:26:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333770#M8575</guid>
      <dc:creator>WilliamKimrey</dc:creator>
      <dc:date>2011-02-17T17:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Editing FeatureLayer and Validation</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333771#M8576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Since you are dealing with multiple feature layers, I would advise that you set default values at the SDE level, i.e. for the required CodedValueDomain attributes associate a default value, say empty string as Code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Fields at the level of feature services are always considered as nullable data types and if you need to force them to be required an alternative approach would be extending current FeatureDataForm control and specifically look into the following method:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;private &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; HasChange(&lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 2; font-family: Consolas;"&gt;Control&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; control, &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;object&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; valueInGraphic, &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 2; font-family: Consolas;"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; type, &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;out &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 2; font-family: Consolas;"&gt;bool&lt;/SPAN&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt; hasError)&lt;/SPAN&gt;
&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt;{&lt;/SPAN&gt;
&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt;&lt;SPAN style="font-size: 2; font-family: Consolas;"&gt;}&lt;/SPAN&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:48:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333771#M8576</guid>
      <dc:creator>AliMirzabeigi</dc:creator>
      <dc:date>2021-12-11T15:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: Editing FeatureLayer and Validation</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333772#M8577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the assistance.&amp;nbsp; Sadly, I'm not very good at extending controls.&amp;nbsp; I almost always mess something up and I'm kind of behind schedule already so I need to find a workaround ASAP.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In light of that, I've done the following which seems like it'll serve my purpose for now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the BeginSaveEdits event, I loop through the graphics to be added.&amp;nbsp; I then loop through every attribute in each graphic.&amp;nbsp; Since I know which fields have to have values in them, I set up a series of checks to see if that graphic's attributes contain those fields and if they are null.&amp;nbsp; If this is true, I show a messagebox saying the value's not set and cancel the edit.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This would work great, but for some reason, the edit is not being canceled.&amp;nbsp; The EndSaveEdits event is still firing and causing the user to start over and re-add the graphic instead of just fixing the offending attribute and saving again.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just to clarify, to cancel the edit I put "e.Cancel = true;" in my code.&amp;nbsp; If this is not correct, please let me know.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Will&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Feb 2011 18:21:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333772#M8577</guid>
      <dc:creator>WilliamKimrey</dc:creator>
      <dc:date>2011-02-17T18:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Editing FeatureLayer and Validation</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333773#M8578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As for the e.Cancel on BeginSaveEdits, this is a related thread: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/20915-I-set-BeginEditEventArgs.Cancel-true-but-edits-get-saved-anyway" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/20915-I-set-BeginEditEventArgs.Cancel-true-but-edits-get-saved-anyway&lt;/A&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For workaround, you can set FeatureLayer AutoSave to False, perform your check on EditEnded and explicitly call SaveEdits(). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you using TemplatePicker to add features? If yes, TemplatePicker also has EditCompleted event.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
t.EditCompleted += (s, e) =&amp;gt;
{
 if (e.Action == Editor.EditAction.Add)
 {
&amp;nbsp; foreach (var edit in e.Edits)
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; Graphic g = edit.Graphic;
&amp;nbsp;&amp;nbsp; bool requiredFieldSupplied = true;
&amp;nbsp;&amp;nbsp; foreach (var item in g.Attributes)
&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; //TODO: check required field is not null
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (item.Key == "MyRequiredFieldName" &amp;amp;&amp;amp; item.Value == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; requiredFieldSupplied = false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; FeatureLayer l = edit.Layer as FeatureLayer;
&amp;nbsp;&amp;nbsp; if (requiredFieldSupplied)
&amp;nbsp;&amp;nbsp;&amp;nbsp; l.SaveEdits();
&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show("MyRequiredFieldName cannot be null");
&amp;nbsp; }
 }
};
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:48:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/editing-featurelayer-and-validation/m-p/333773#M8578</guid>
      <dc:creator>JenniferNery</dc:creator>
      <dc:date>2021-12-11T15:48:13Z</dc:date>
    </item>
  </channel>
</rss>

