ListBox.SelectedIndices Özellik

Tanım

içinde seçili durumdaki tüm öğelerin ListBoxsıfır tabanlı dizinlerini içeren bir koleksiyon alır.

public:
 property System::Windows::Forms::ListBox::SelectedIndexCollection ^ SelectedIndices { System::Windows::Forms::ListBox::SelectedIndexCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.ListBox.SelectedIndexCollection SelectedIndices { get; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectedIndices : System.Windows.Forms.ListBox.SelectedIndexCollection
Public ReadOnly Property SelectedIndices As ListBox.SelectedIndexCollection

Özellik Değeri

ListBox.SelectedIndexCollection

ListBox.SelectedIndexCollection Denetimde seçili durumdaki öğelerin dizinlerini içeren. Seçili öğe yoksa boş ListBox.SelectedIndexCollection bir öğe döndürülür.

Öznitelikler

Örnekler

Aşağıdaki kod örneği, öğesindeki arama ListBoxmetninin FindString tüm örneklerini aramak için yönteminin nasıl kullanılacağını gösterir. Örnek, içindeki tüm öğelerde sürekli arama yapabileceğiniz başlangıç arama dizini belirtmenizi sağlayan yönteminin ListBoxsürümünü FindString kullanır. Örnekte ayrıca, özyinelemeli aramayı önlemek için yöntemin FindString öğe listesinin en altına ulaştıktan sonra listenin en üstünden aramaya ne zaman başladığının nasıl belirleneceği de gösterilmektedir. öğeleri içinde ListBoxbulunduktan sonra yöntemi kullanılarak SetSelected seçilir.

private:
   void FindAllOfMyString( String^ searchString )
   {
      // Set the SelectionMode property of the ListBox to select multiple items.
      listBox1->SelectionMode = SelectionMode::MultiExtended;

      // Set our intial index variable to -1.
      int x = -1;

      // If the search string is empty exit.
      if ( searchString->Length != 0 )
      {
         // Loop through and find each item that matches the search string.
         do
         {
            // Retrieve the item based on the previous index found. Starts with -1 which searches start.
            x = listBox1->FindString( searchString, x );

            // If no item is found that matches exit.
            if ( x != -1 )
            {
               // Since the FindString loops infinitely, determine if we found first item again and exit.
               if ( listBox1->SelectedIndices->Count > 0 )
               {
                  if ( x == listBox1->SelectedIndices[ 0 ] )
                                    return;
               }

               // Select the item in the ListBox once it is found.
               listBox1->SetSelected( x, true );
            }
         }
         while ( x != -1 );
      }
   }
private void FindAllOfMyString(string searchString)
{
   // Set the SelectionMode property of the ListBox to select multiple items.
   listBox1.SelectionMode = SelectionMode.MultiExtended;
   
   // Set our intial index variable to -1.
   int x =-1;
   // If the search string is empty exit.
   if (searchString.Length != 0)
   {
      // Loop through and find each item that matches the search string.
      do
      {
         // Retrieve the item based on the previous index found. Starts with -1 which searches start.
         x = listBox1.FindString(searchString, x);
         // If no item is found that matches exit.
         if (x != -1)
         {
            // Since the FindString loops infinitely, determine if we found first item again and exit.
            if (listBox1.SelectedIndices.Count > 0)
            {
               if(x == listBox1.SelectedIndices[0])
                  return;
            }
            // Select the item in the ListBox once it is found.
            listBox1.SetSelected(x,true);
         }
      }while(x != -1);
   }
}
Private Sub FindAllOfMyString(ByVal searchString As String)
   ' Set the SelectionMode property of the ListBox to select multiple items.
   listBox1.SelectionMode = SelectionMode.MultiExtended

   ' Set our intial index variable to -1.
   Dim x As Integer = -1
   ' If the search string is empty exit.
   If searchString.Length <> 0 Then
      ' Loop through and find each item that matches the search string.
      Do
         ' Retrieve the item based on the previous index found. Starts with -1 which searches start.
         x = listBox1.FindString(searchString, x)
         ' If no item is found that matches exit.
         If x <> -1 Then
            ' Since the FindString loops infinitely, determine if we found first item again and exit.
            If ListBox1.SelectedIndices.Count > 0 Then
               If x = ListBox1.SelectedIndices(0) Then
                  Return
               End If
            End If
            ' Select the item in the ListBox once it is found.
            ListBox1.SetSelected(x, True)
         End If
      Loop While x <> -1
   End If
End Sub

Açıklamalar

Çoklu seçim ListBoxiçin, bu özellik içinde seçilen ListBoxtüm öğelerin dizinlerini içeren bir koleksiyon döndürür. Tek seçimli ListBoxiçin, bu özellik içinde seçilen tek öğenin ListBoxdizinini içeren tek bir öğe içeren bir koleksiyon döndürür. Koleksiyonun öğelerini işleme hakkında daha fazla bilgi için bkz ListBox.SelectedIndexCollection. .

sınıfı, ListBox seçili öğelere başvurmak için çeşitli yollar sağlar. özelliğini kullanarak SelectedIndices tek seçimli ListBoxbir öğede seçili durumdaki öğenin dizin konumunu almak yerine özelliğini kullanabilirsiniz SelectedIndex . öğesinde ListBoxseçili durumda olan öğeyi almak istiyorsanız, öğenin dizin konumu yerine özelliğini kullanın SelectedItem . Ayrıca, birden çok seçimli SelectedItems ListBoxbir içindeki tüm seçili öğeleri almak istiyorsanız özelliğini kullanabilirsiniz.

Şunlara uygulanır

Ayrıca bkz.