Rediger

Del via


IValueProvider.SetValue(String) Method

Definition

Sets the value of a control.

public:
 void SetValue(System::String ^ value);
public void SetValue (string value);
abstract member SetValue : string -> unit
Public Sub SetValue (value As String)

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.

/// <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;
}
''' <summary>
''' Sets the value of the control.
''' </summary>
''' <param name="value">
''' The new value.
''' </param>
Private Sub SetValue(ByVal value As String) Implements IValueProvider.SetValue
    If (CType(Me, IValueProvider)).IsReadOnly Then
        Throw New InvalidOperationException("Operation cannot be performed.")
    End If
    ' Arbitrary string length limit.
    If value.Length > 5 Then
        Throw New ArgumentOutOfRangeException("String is greater than five characters in length.")
    End If
    controlValue = value
End Sub

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