ListControl.SelectedValue プロパティ
アセンブリ: System.Web (system.web.dll 内)

<ThemeableAttribute(False)> _ <BindableAttribute(True, BindingDirection.TwoWay)> _ Public Overridable Property SelectedValue As String
Dim instance As ListControl Dim value As String value = instance.SelectedValue instance.SelectedValue = value
[ThemeableAttribute(false)] [BindableAttribute(true, BindingDirection.TwoWay)] public virtual string SelectedValue { get; set; }
[ThemeableAttribute(false)] [BindableAttribute(true, BindingDirection::TwoWay)] public: virtual property String^ SelectedValue { String^ get (); void set (String^ value); }
/** @property */ public String get_SelectedValue () /** @property */ public void set_SelectedValue (String value)
リスト コントロール内の選択されている項目の値。既定値は空の文字列 ("") です。

このプロパティは、選択した ListItem の Value プロパティを返します。SelectedValue プロパティは、通常、リスト コントロール内で選択されている項目の値を確認するときに使用します。複数の項目が選択されている場合は、最小のインデックスを持つ選択項目の値が返されます。項目が選択されていない場合は、空の文字列 ("") が返されます。
また、項目の値を使用して SelectedValue プロパティを設定すると、このプロパティでリスト コントロールの項目を選択することもできます。指定した値を含む項目がリスト コントロール内にない場合は、System.ArgumentOutOfRangeException がスローされます。
このプロパティは、テーマ別またはスタイル シート テーマ別に設定することはできません。詳細については、ThemeableAttribute、ASP.NET のテーマとスキンの概要 の各トピックを参照してください。

SelectedValue プロパティを使用して、ListBox コントロール内の項目を選択する方法を次の例に示します。このプロパティを使用すると、選択されている項目の値を取得することもできます。
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Button_Click(sender As Object, e As EventArgs) ' Perform this operation in a try-catch block in case the item is not found. Try List.SelectedValue = ItemTextBox.Text MessageLabel.Text = "You selected " & List.SelectedValue + "." Catch ex As Exception List.SelectedValue = Nothing MessageLabel.Text = "Item not found in ListBox control." End Try End Sub </script> </head> <body> <form runat="server"> <h3> ListControl SelectedValue Example </h3> <asp:ListBox ID="List" runat="server"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> </asp:ListBox> <hr> Enter the value of the item to select: <br> <asp:TextBox ID="ItemTextBox" MaxLength="6" Text="Item 1" runat="server"/> <asp:Button ID="SelectButton" Text="Select Item" OnClick="Button_Click" runat="server"/> <br><br> <asp:Label ID="MessageLabel" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void Button_Click(Object sender, EventArgs e) { // Perform this operation in a try-catch block in case the item is not found. try { List.SelectedValue = ItemTextBox.Text; MessageLabel.Text = "You selected " + List.SelectedValue + "."; } catch (Exception ex) { List.SelectedValue = null; MessageLabel.Text = "Item not found in ListBox control."; } } </script> </head> <body> <form runat="server"> <h3> ListControl SelectedValue Example </h3> <asp:ListBox ID="List" runat="server"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> </asp:ListBox> <hr> Enter the value of the item to select: <br> <asp:TextBox ID="ItemTextBox" MaxLength="6" Text="Item 1" runat="server"/> <asp:Button ID="SelectButton" Text="Select Item" OnClick="Button_Click" runat="server"/> <br><br> <asp:Label ID="MessageLabel" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ListControl.SelectedValue プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As ListControl Dim value As Object value = instance.SelectedValue instance.SelectedValue = value
[BindableAttribute(true)] public: property Object^ SelectedValue { Object^ get (); void set (Object^ value); }
/** @property */ public Object get_SelectedValue () /** @property */ public void set_SelectedValue (Object value)
ValueMember プロパティで指定したデータ ソースのメンバの値を格納しているオブジェクト。


ValueMember にプロパティを指定しない場合、SelectedValue はオブジェクトの ToString メソッドの結果を返します。
SelectedIndex、SelectedValue、および FormattingEnabled は、次のように関連します。

ValueMember プロパティで指定されたプロパティの値を返す SelectedValue を次のコード例に示します。このコードは、ListControl クラスの概要で紹介されている例からの抜粋です。コード全体については、ListControl を参照してください。
Private Sub ListBox1_SelectedValueChanged(sender As Object, e As EventArgs) If ListBox1.SelectedIndex <> - 1 Then textBox1.Text = ListBox1.SelectedValue.ToString() End If End Sub 'ListBox1_SelectedValueChanged
private void ListBox1_SelectedValueChanged(object sender, EventArgs e) { if (ListBox1.SelectedIndex != -1) textBox1.Text = ListBox1.SelectedValue.ToString(); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ListControl.SelectedValueのページへのリンク