다음을 통해 공유


ListControl.SelectedValue 속성

정의

속성에 지정된 ValueMember 멤버 속성의 값을 가져오거나 설정합니다.

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; }
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.Browsable(false)]
public object? SelectedValue { get; set; }
[<System.ComponentModel.Bindable(true)>]
[<System.ComponentModel.Browsable(false)>]
member this.SelectedValue : obj with get, set
Public Property SelectedValue As Object

속성 값

속성에 지정된 ValueMember 데이터 원본의 멤버 값을 포함하는 개체입니다.

특성

예외

할당된 값 또는 빈 문자열("")입니다 null .

예제

다음 코드 예제에서는 속성에 SelectedValue 의해 지정 된 속성의 값을 반환 하는 방법을 보여 있습니다 ValueMember . 이 코드는 클래스 개요에 표시된 예제에서 발췌한 ListControl 것입니다. 전체 코드 목록을 참조하세요 ListControl .

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
End Class

설명

속성이 지정 ValueMemberSelectedValue 되지 않은 경우 개체 메서드의 ToString 결과를 반환합니다.

SelectedIndex, SelectedValueFormattingEnabled 다음과 같이 관련됩니다.

적용 대상

추가 정보