Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Ruft die Anzahl der Elemente in der Auflistung ab.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public ReadOnly Property Count As Integer
'Usage
Dim instance As SelectedIndexCollection
Dim value As Integer
value = instance.Count
public int Count { get; }
public:
virtual property int Count {
int get () sealed;
}
/** @property */
public final int get_Count ()
public final function get Count () : int
Eigenschaftenwert
Die Anzahl der Elemente in der Auflistung.
Hinweise
Mit dieser Eigenschaft können Sie die Anzahl der in der ListBox ausgewählten Elemente bestimmen. Anschließend können Sie diesen Wert verwenden, wenn die Werte der Auflistung durchlaufen werden sollen und die Anzahl der Wiederholungen für das Durchlaufen der Schleife festgelegt werden muss. Wenn die SelectionMode-Eigenschaft von ListBox nicht auf SelectionMode.MultiSimple oder SelectionMode.MultiExtended festgelegt ist, gibt diese Eigenschaft immer einen Wert von null (0) oder eins (1) zurück, abhängig davon, ob ein Element ausgewählt ist.
Beispiel
Das folgende Beispiel veranschaulicht, wie mithilfe der FindString-Methode in den Elementen der ListBox nach allen Instanzen des Suchtexts gesucht wird. Im Beispiel wird die Version der FindString-Methode verwendet, mit der Sie einen Startindex für die Suche angeben können, ab dem die Suche in allen Elementen in der ListBox fortgesetzt wird. Darüber hinaus wird veranschaulicht, wie festgestellt wird, dass die FindString-Methode die Suche am Anfang der Liste fortsetzt, nachdem das Ende der Liste erreicht wurde, sodass eine rekursive Suche vermieden wird. Wenn Elemente in der ListBox gefunden wurden, werden sie mithilfe der SetSelected-Methode ausgewählt.
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
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 void FindAllOfMyString(String searchString)
{
// Set the SelectionMode property of the ListBox to
// select multiple items.
listBox1.set_SelectionMode(SelectionMode.MultiExtended);
// Set our intial index variable to -1.
int x = -1;
// If the search string is empty exit.
if (searchString.get_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.get_SelectedIndices().get_Count() > 0) {
if (x == listBox1.get_SelectedIndices().get_Item(0)) {
return;
}
}
// Select the item in the ListBox once it is found.
listBox1.SetSelected(x, true);
}
} while (x != -1);
}
} //FindAllOfMyString
} //Form1
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ListBox.SelectedIndexCollection-Klasse
ListBox.SelectedIndexCollection-Member
System.Windows.Forms-Namespace