ListBox.SelectedIndexChanged イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ListBox.SelectedIndexChanged イベントの意味・解説 

ListBox.SelectedIndexChanged イベント

SelectedIndex プロパティ変更され場合発生します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Event SelectedIndexChanged As
 EventHandler
Dim instance As ListBox
Dim handler As EventHandler

AddHandler instance.SelectedIndexChanged, handler
public event EventHandler SelectedIndexChanged
/** @event */
public void add_SelectedIndexChanged (EventHandler
 value)

/** @event */
public void remove_SelectedIndexChanged (EventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

SelectedIndexChanged イベント使用して、他の ListBox コントロール内で項目を検索して選択する方法次のコード例示します。この例では、SelectedIndexChanged イベント使用してListBox 内の選択項目がいつ変更されたかを判断してます。次に、このコード例は、SelectedItem プロパティ使用して項目のテキスト読み取り最初ListBoxSelectedItem返されテキスト使用して他の ListBox にある FindString メソッド呼び出してます。他の ListBox で項目が見つかった場合、その項目は選択されています。この例では、listBox1 および listBox2 という名前の 2 つListBox コントロールフォーム追加されており、この 2 つListBox コントロール両方同一の項目が格納されている必要がありますまた、この例で定義されているイベント処理メソッドが、listBox1SelectedIndexChanged イベント接続されている必要もあります

Private Sub listBox1_SelectedIndexChanged(ByVal
 sender As Object, ByVal
 e As System.EventArgs) Handles listBox1.SelectedIndexChanged
   ' Get the currently selected item in the ListBox.
   Dim curItem As String
 = listBox1.SelectedItem.ToString()

   ' Find the string in ListBox2.
   Dim index As Integer
 = listBox2.FindString(curItem)
   ' If the item was not found in ListBox 2 display a message box, otherwise
 select it in ListBox2.
   If index = -1 Then
      MessageBox.Show("Item is not available in ListBox2")
   Else
      listBox2.SetSelected(index, True)
   End If
End Sub
private void listBox1_SelectedIndexChanged(object
 sender, System.EventArgs e)
{
   // Get the currently selected item in the ListBox.
   string curItem = listBox1.SelectedItem.ToString();

   // Find the string in ListBox2.
   int index = listBox2.FindString(curItem);
   // If the item was not found in ListBox 2 display a message box,
 otherwise select it in ListBox2.
   if(index == -1)
      MessageBox.Show("Item is not available in ListBox2");
   else
      listBox2.SetSelected(index,true);
}
private:
   void listBox1_SelectedIndexChanged( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Get the currently selected item in the ListBox.
      String^ curItem = listBox1->SelectedItem->ToString();

      // Find the string in ListBox2.
      int index = listBox2->FindString( curItem );

      // If the item was not found in ListBox 2 display a message box
,
      //  otherwise select it in ListBox2.
      if ( index == -1 )
            MessageBox::Show( "Item is not available in ListBox2"
 );
      else
            listBox2->SetSelected( index, true );
   }
private void listBox1_SelectedIndexChanged(Object
 sender, 
    System.EventArgs e)
{
    // Get the currently selected item in the ListBox.
    String curItem = listBox1.get_SelectedItem().ToString();
    // Find the string in ListBox2.
    int index = listBox2.FindString(curItem);
    // If the item was not found in ListBox 2 display a message box,
 
    // otherwise select it in ListBox2.
    if (index == -1) {
        MessageBox.Show("Item is not available in ListBox2");
    }
    else {
        listBox2.SetSelected(index, true);
    }
} //listBox1_SelectedIndexChanged 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からListBox.SelectedIndexChanged イベントを検索した結果を表示しています。
Weblioに収録されているすべての辞書からListBox.SelectedIndexChanged イベントを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からListBox.SelectedIndexChanged イベント を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ListBox.SelectedIndexChanged イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ListBox.SelectedIndexChanged イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS