ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Editing.Attributes Namespace / Inspector Class / TrySetValue Method
A string value to search for a desired attribute field name. This search is case insensitive.
The value to apply to the attribute.
Example

In This Topic
    TrySetValue Method
    In This Topic
    Sets the value of the attribute specified by the fieldName.
    Syntax
    public bool TrySetValue( 
       string fieldName,
       object value
    )
    Public Function TrySetValue( _
       ByVal fieldName As String, _
       ByVal value As Object _
    ) As Boolean

    Parameters

    fieldName
    A string value to search for a desired attribute field name. This search is case insensitive.
    value
    The value to apply to the attribute.

    Return Value

    True if the inspector contains an attribute with the specified fieldName. False otherwise.
    Example
    Adds a custom validation rule to the "Mineral" field of the specified feature layer.
    await QueuedTask.Run(() =>
    {
      var insp = new Inspector();
      insp.LoadSchema(featureLayer);
    
      bool success = insp.TrySetValue("mineral", "Salt");
      object result = null;
      success = insp.TryGetValue("mineral", out result);
      if (result != null && success)
      {
        MessageBox.Show($"Successfully stored and retrieved the value of field 'Mineral': {result.ToString()}");
      }
    
      var attrib = insp.Where(a => a.FieldName == "Mineral").First();
      attrib.AddValidate(() =>
      {
        if (attrib.CurrentValue.ToString() == "Salt")
        {
          return [];
        }
        else
        {
          return [ArcGIS.Desktop.Editing.Attributes.Attribute.ValidationError.Create("Error", Severity.Low)];
        }
      });
    });
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.8 or higher.
    See Also