IValueProvider.SetValue(String) Method

Definition

Sets the value of a control.

C#
public void SetValue(string value);

Parameters

value
String

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

Exceptions

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.

Examples

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

C#
/// <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;
}

Remarks

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

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10