Share via


ListBox.ObjectCollection.RemoveAt(Int32) Yöntem

Tanım

Koleksiyon içinde belirtilen dizindeki öğeyi kaldırır.

public:
 virtual void RemoveAt(int index);
public void RemoveAt (int index);
abstract member RemoveAt : int -> unit
override this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)

Parametreler

index
Int32

Kaldırılacak öğenin sıfır tabanlı dizini.

Uygulamalar

Özel durumlar

index parametresi sıfırdan küçük veya sınıfın özelliğinin CountListBox.ObjectCollection değerine eşit veya ondan büyük.

Örnekler

Aşağıdaki kod örneği, şu anda seçili olan öğeyi görüntüleme alanındaki ListBoxöğe listesinin en üstüne taşımak için özelliğiyle özelliğinin TopIndex nasıl kullanılacağını SelectedIndex gösterir. Örnekte, sınıfın yöntemini kullanarak öğelerin nasıl kaldırılacağı ve yöntemini System.Windows.Forms.ListBox.ObjectCollection kullanarak RemoveAt tüm öğe seçiminin ClearSelected nasıl temizılacağı gösterilmektedir. Kod önce seçili durumdaki ListBox öğeyi listenin en üstüne taşır. Kod daha sonra seçili durumdaki öğeden önceki tüm öğeleri kaldırır ve içindeki ListBoxtüm seçimleri temizler. Bu örnek, içeren öğelerin forma eklenmesini ve içinde bir öğenin seçili ListBoxolmasını gerektirirListBox.

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 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

Açıklamalar

Listeden bir öğeyi kaldırdığınızda, listedeki sonraki öğeler için dizinler değişir. Kaldırılan öğe hakkındaki tüm bilgiler silinir. Listeden kaldırılacak öğenin dizinini belirterek listeden belirli bir öğeyi kaldırmak için bu yöntemi kullanabilirsiniz. Öğenin dizini yerine kaldırılacak öğeyi belirtmek için yöntemini kullanın Remove . Listedeki tüm öğeleri kaldırmak için yöntemini kullanın Clear .

Şunlara uygulanır

Ayrıca bkz.