Export (0) Print
Expand All

ListControl.SelectedValue Property

Gets or sets the value of the member property specified by the ValueMember property.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

'Declaration
<BindableAttribute(True)> _
Public Property SelectedValue As Object
'Usage
Dim instance As ListControl
Dim value As Object

value = instance.SelectedValue

instance.SelectedValue = value
/** @property */
public Object get_SelectedValue ()

/** @property */
public void set_SelectedValue (Object value)

public function get SelectedValue () : Object

public function set SelectedValue (value : Object)

Not applicable.

Property Value

An object containing the value of the member of the data source specified by the ValueMember property.

Exception typeCondition

InvalidOperationException

The assigned value is a null reference (Nothing in Visual Basic) or the empty string ("").

If a property is not specified in ValueMember, SelectedValue returns the results of the ToString method of the object.

SelectedIndex, SelectedValue, and FormattingEnabled are related as follows:

  • If FormattingEnabled is false, SelectedIndex will not be set to -1 when SelectedValue is blank.

  • If FormattingEnabled is true, SelectedIndex will be set to -1 when SelectedValue is blank.

The following code example shows the SelectedValue returning the value of the property specified by the ValueMember property. This code is an excerpt from the example shown in the ListControl class overview. See ListControl for the whole code listing.

Private Sub ListBox1_SelectedValueChanged(sender As Object, e As EventArgs)
   If ListBox1.SelectedIndex <> - 1 Then
      textBox1.Text = ListBox1.SelectedValue.ToString()
   End If
End Sub 'ListBox1_SelectedValueChanged

private void listBox1_SelectedValueChanged(Object sender, EventArgs e)
{
    if (listBox1.get_SelectedIndex() != -1) {
        textBox1.set_Text(listBox1.get_SelectedValue().ToString());
    }
} //listBox1_SelectedValueChanged

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft