# ListView.SearchForVirtualItemListView.SearchForVirtualItemListView.SearchForVirtualItemListView.SearchForVirtualItem Event

## Définition

Se produit lorsque le ListView est en mode virtuel et une recherche est en cours.Occurs when the ListView is in virtual mode and a search is taking place.

``````public:
event System::Windows::Forms::SearchForVirtualItemEventHandler ^ SearchForVirtualItem;``````
``public event System.Windows.Forms.SearchForVirtualItemEventHandler SearchForVirtualItem;``
``member this.SearchForVirtualItem : System.Windows.Forms.SearchForVirtualItemEventHandler ``
``Public Custom Event SearchForVirtualItem As SearchForVirtualItemEventHandler ``

## Exemples

L’exemple de code suivant illustre l’utilisation de ce membre.The following code example demonstrates the use of this member. Dans l’exemple, une recherche retourne le plus proche à un entier dans une liste des 10 000 premiers carrés.In the example, a search returns the nearest match to a specified integer in a list of the first ten thousand squares. Cet exemple de code fait partie d’un exemple plus complet fourni pour le VirtualMode propriété.This code example is part of a larger example provided for the VirtualMode property.

``````//This event handler enables search functionality, and is called
//for every search request when in Virtual mode.
void listView1_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
{
//We've gotten a search request.
//In this example, finding the item is easy since it's
//just the square of its index.  We'll take the square root
//and round.
double x = 0;
if (Double.TryParse(e.Text, out x)) //check if this is a valid search
{
x = Math.Sqrt(x);
x = Math.Round(x);
e.Index = (int)x;

}
//If e.Index is not set, the search returns null.
//Note that this only handles simple searches over the entire
//list, ignoring any other settings.  Handling Direction, StartIndex,
//and the other properties of SearchForVirtualItemEventArgs is up
//to this handler.
}
``````
``````'This event handler enables search functionality, and is called
'for every search request when in Virtual mode.
Private Sub listView1_SearchForVirtualItem(ByVal sender As Object, ByVal e As SearchForVirtualItemEventArgs) Handles listView1.SearchForVirtualItem
'We've gotten a search request.
'In this example, finding the item is easy since it's
'just the square of its index.  We'll take the square root
'and round.
Dim x As Double = 0
If [Double].TryParse(e.Text, x) Then 'check if this is a valid search
x = Math.Sqrt(x)
x = Math.Round(x)
e.Index = Fix(x)
End If
'Note that this only handles simple searches over the entire
'list, ignoring any other settings.  Handling Direction, StartIndex,
'and the other properties of SearchForVirtualItemEventArgs is up
'to this handler.
End Sub
``````

## Remarques

Cet événement se produit lorsqu’un ListView est en mode virtuel et le FindNearestItem ou FindItemWithText méthode est appelée.This event occurs when a ListView is in virtual mode and the FindNearestItem or FindItemWithText method is called. Lors du traitement de cet événement, vous devez déterminer quel élément dans la liste d’éléments fournie par le Items correspond aux critères de recherche de la propriété et affecter le SearchForVirtualItemEventArgs.Index index à la propriété de la ListViewItem.When handling this event, you should calculate which item from the list of items supplied by the Items property matches the search criteria and set the SearchForVirtualItemEventArgs.Index property to the index of the ListViewItem. Si un élément n’est pas fourni, FindNearestItem et FindItemWithText retournera `null`.If an item is not provided, FindNearestItem and FindItemWithText will return `null`.

Pour plus d'informations sur la gestion des événements, voir gestion et déclenchement d’événements.For more information about handling events, see Handling and Raising Events.