ListControl.SelectedValue ListControl.SelectedValue ListControl.SelectedValue ListControl.SelectedValue Property

定義

取得または設定によって指定されたメンバー プロパティの値、ValueMemberプロパティ。Gets or sets the value of the member property specified by the ValueMember property.

public:
 property System::Object ^ SelectedValue { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.Browsable(false)]
public object SelectedValue { get; set; }
member this.SelectedValue : obj with get, set
Public Property SelectedValue As Object

プロパティ値

指定されたデータ ソースのメンバーの値を格納するオブジェクト、ValueMemberプロパティ。An object containing the value of the member of the data source specified by the ValueMember property.

例外

代入された値がnullまたは空の文字列 ("")。The assigned value is null or the empty string ("").

次のコード例は、SelectedValueで指定されたプロパティの値を返す、ValueMemberプロパティ。The following code example shows the SelectedValue returning the value of the property specified by the ValueMember property. このコードは、抜粋の例に示すように、ListControlクラスの概要。This code is an excerpt from the example shown in the ListControl class overview. 参照してくださいListControl全体のコードの一覧。See ListControl for the whole code listing.

void ListBox1_SelectedValueChanged( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   textBox1->Text="";
   if ( ListBox1->SelectedIndex != -1 )
         textBox1->Text = ListBox1->SelectedValue->ToString();
}
private void ListBox1_SelectedValueChanged(object sender, EventArgs e)
{
    if (ListBox1.SelectedIndex != -1)
    {
        textBox1.Text = ListBox1.SelectedValue.ToString();
        // If we also wanted to get the displayed text we could use
        // the SelectedItem item property:
        // string s = ((USState)ListBox1.SelectedItem).LongName;
    }
}
    Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As EventArgs)
        If ListBox1.SelectedIndex <> -1 Then
            textBox1.Text = ListBox1.SelectedValue.ToString()
            ' If we also wanted to get the displayed text we could use
            ' the SelectedItem item property:
            ' Dim s = CType(ListBox1.SelectedItem, USState).LongName
        End If
    End Sub 'ListBox1_SelectedValueChanged
End Class 'ListBoxSample3

注釈

プロパティが指定されていない場合ValueMemberSelectedValueの結果を返します、ToStringオブジェクトのメソッド。If a property is not specified in ValueMember, SelectedValue returns the results of the ToString method of the object.

SelectedIndexSelectedValue、およびFormattingEnabled次のように関連します。SelectedIndex, SelectedValue, and FormattingEnabled are related as follows:

適用対象

こちらもご覧ください