This documentation is archived and is not being maintained.

ListControl.SelectedValue Property

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

[Visual Basic]
Public Property SelectedValue As Object
public object SelectedValue {get; set;}
public: __property Object* get_SelectedValue();
public: __property void set_SelectedValue(Object*);
public function get SelectedValue() : Object;
public function set SelectedValue(Object);

Property Value

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


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


[Visual Basic, C#, C++] The following 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.

[Visual Basic] 
Private Sub ListBox1_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged
    If ListBox1.SelectedIndex <> -1 Then
        textBox1.Text = ListBox1.SelectedValue
    End If
End Sub

private void ListBox1_SelectedValueChanged(object sender, EventArgs e)
    if (ListBox1.SelectedIndex != -1)
        textBox1.Text = ListBox1.SelectedValue.ToString();

    void ListBox1_SelectedValueChanged(Object* /*sender*/, EventArgs* /*e*/)
        if (ListBox1->SelectedIndex != -1)
            textBox1->Text = ListBox1->SelectedValue->ToString();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

ListControl Class | ListControl Members | System.Windows.Forms Namespace | ValueMember