ListControl.SelectedValue 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
속성에 지정된 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, SelectedValue및 FormattingEnabled 다음과 같이 관련됩니다.
이
falseSelectedIndex 경우 FormattingEnabled 비어 있으면 -1 SelectedValue 설정되지 않습니다.이
trueSelectedIndex 경우 FormattingEnabled 비어 있으면 -1 SelectedValue 설정됩니다.