IValueProvider.SetValue Method (String)


Sets the value of a control.

Namespace:   System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

void SetValue(
	string value


Type: System.String

The value to set. The provider is responsible for converting the value to the appropriate data type.

Exception Condition

If locale-specific information is passed to a control in an incorrect format such as an incorrectly formatted date.


If a new value cannot be converted from a string to a format the control recognizes.


When an attempt is made to manipulate a control that is not enabled.

Single-line edit controls support programmatic access to their contents by implementing IValueProvider. However, multi-line edit controls do not implement IValueProvider; instead they provide access to their content by implementing ITextProvider.

Controls such as ListItem and TreeItem must implement IValueProvider if the value of any of the items is editable, regardless of the current edit mode of the control. The parent control must also implement IValueProvider if the child items are editable.

Editable list item.

Example of an Editable List Item

The following example code demonstrates a custom control that allows its value to be set to a string of limited length.

/// <summary>
/// Sets the value of the control.
/// </summary>
/// <param name="value">
/// The new value.
/// </param>
void IValueProvider.SetValue(string value)
    if (((IValueProvider)this).IsReadOnly)
        throw new InvalidOperationException(
            "Operation cannot be performed.");
    // Arbitrary string length limit.
    if (value.Length > 5)
        throw new ArgumentOutOfRangeException(
            "String is greater than five characters in length.");
    controlValue = value;

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top