ListView.SearchForVirtualItem Evento

Definición

Se produce cuando el control ListView está en modo virtual y se está realizando una búsqueda.

public:
 event System::Windows::Forms::SearchForVirtualItemEventHandler ^ SearchForVirtualItem;
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 

Tipo de evento

SearchForVirtualItemEventHandler

Ejemplos

En el ejemplo de código siguiente se muestra el uso de este miembro. En el ejemplo, una búsqueda devuelve la coincidencia más cercana a un entero especificado en una lista de los primeros diez mil cuadrados. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la VirtualMode propiedad .

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

Comentarios

Este evento se produce cuando ListView se encuentra en modo virtual y se llama al FindNearestItem método o FindItemWithText . Al controlar este evento, debe calcular qué elemento de la lista de elementos proporcionados por la Items propiedad coincide con los criterios de búsqueda y establecer la SearchForVirtualItemEventArgs.Index propiedad en el índice de ListViewItem. Si no se proporciona FindNearestItem un elemento y FindItemWithText devolverá null.

Para obtener más información sobre el manejo de eventos, consulte controlar y provocar eventos.

Se aplica a