ListBox.ObjectCollection.RemoveAt メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ListBox.ObjectCollection.RemoveAt メソッドの意味・解説 

ListBox.ObjectCollection.RemoveAt メソッド

コレクション内の指定されインデックスにある項目を削除します

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

Public Sub RemoveAt ( _
    index As Integer _
)
Dim instance As ObjectCollection
Dim index As Integer

instance.RemoveAt(index)
public void RemoveAt (
    int index
)
public final void RemoveAt (
    int index
)

パラメータ

index

削除する項目の 0 から始まるインデックス

例外例外
例外種類条件

ArgumentOutOfRangeException

index パラメータの値がゼロ未満か、ListBox.ObjectCollection クラスCount プロパティの値以上です。

解説解説
使用例使用例

SelectedIndex プロパティと TopIndex プロパティ使用し、現在選択されている項目を ListBox表示領域内の項目リスト先頭移動する方法次のコード例示します。さらに、System.Windows.Forms.ListBox.ObjectCollection クラスRemoveAt メソッド使用して項目を削除する方法、ClearSelected メソッド使用してすべての項目の選択解除する方法についても示します。このコード最初にListBox で現在選択されている項目をリスト先頭移動します。このコード次に、現在選択されている項目より前にある項目をすべて削除しListBox 内の選択をすべて解除します。この例では、項目を含む ListBoxフォーム追加されていて、いずれかの項目が ListBox で現在選択されている必要があります

Private Sub RemoveTopItems()
   ' Determine if the currently selected item in the ListBox 
   ' is the item displayed at the top in the ListBox.
   If listBox1.TopIndex <> listBox1.SelectedIndex Then
      ' Make the currently selected item the top item in the ListBox.
      listBox1.TopIndex = listBox1.SelectedIndex
   End If
   ' Remove all items before the top item in the ListBox.
   Dim x As Integer
   For x = listBox1.SelectedIndex - 1 To 0
 Step -1
      listBox1.Items.RemoveAt(x)
   Next x

   ' Clear all selections in the ListBox.
   listBox1.ClearSelected()
End Sub 'RemoveTopItems
private void RemoveTopItems()
{
   // Determine if the currently selected item in the ListBox 
   // is the item displayed at the top in the ListBox.
   if (listBox1.TopIndex != listBox1.SelectedIndex)
      // Make the currently selected item the top item in the ListBox.
      listBox1.TopIndex = listBox1.SelectedIndex;

   // Remove all items before the top item in the ListBox.
   for (int x = (listBox1.SelectedIndex -1);
 x >= 0; x--)
   {
      listBox1.Items.RemoveAt(x);
   }

   // Clear all selections in the ListBox.
   listBox1.ClearSelected();
}
private:
   void RemoveTopItems()
   {
      // Determine if the currently selected item in the ListBox 
      // is the item displayed at the top in the ListBox.
      if ( listBox1->TopIndex != listBox1->SelectedIndex
 )

      // Make the currently selected item the top item in the ListBox.
      listBox1->TopIndex = listBox1->SelectedIndex;

      // Remove all items before the top item in the ListBox.
      for ( int x = (listBox1->SelectedIndex
 - 1); x >= 0; x-- )
      {
         listBox1->Items->RemoveAt( x );
      }

      // Clear all selections in the ListBox.
      listBox1->ClearSelected();
   }
private void RemoveTopItems()
{
    // Determine if the currently selected item in the ListBox 
    // is the item displayed at the top in the ListBox.
    if (listBox1.get_TopIndex() != listBox1.get_SelectedIndex())
 {
        // Make the currently selected item the top item in the ListBox.
        listBox1.set_TopIndex(listBox1.get_SelectedIndex());
    }
    // Remove all items before the top item in the ListBox.
    for (int x = listBox1.get_SelectedIndex()
 - 1; x >= 0; x--) {
        listBox1.get_Items().RemoveAt(x);
    }
    // Clear all selections in the ListBox.
    listBox1.ClearSelected();
} //RemoveTopItems
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ListBox.ObjectCollection クラス
ListBox.ObjectCollection メンバ
System.Windows.Forms 名前空間
Clear
Remove


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

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

辞書ショートカット

すべての辞書の索引

ListBox.ObjectCollection.RemoveAt メソッドのお隣キーワード
検索ランキング

   

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



ListBox.ObjectCollection.RemoveAt メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS