Gets or sets currently selected item in the ComboBox.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
'Declaration <BrowsableAttribute(False)> _ <BindableAttribute(True)> _ Public Property SelectedItem As Object 'Usage Dim instance As ComboBox Dim value As Object value = instance.SelectedItem instance.SelectedItem = value
Property ValueType: System.Object
The object that is the currently selected item or Nothing if there is no currently selected item.
When you set the property to an object, the ComboBox attempts to make that object the currently selected one in the list. If the object is found in the list, it is displayed in the edit portion of the ComboBox and the SelectedIndex property is set to the corresponding index. If the object does not exist in the list, the SelectedIndex property is left at its current value.
Private Sub showSelectedButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim selectedIndex As Integer selectedIndex = comboBox1.SelectedIndex Dim selectedItem As Object selectedItem = comboBox1.SelectedItem MessageBox.Show("Selected Item Text: " & selectedItem.ToString() & Microsoft.VisualBasic.Constants.vbCrLf & _ "Index: " & selectedIndex.ToString()) End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.