ListView.SearchForVirtualItem Evento

Definição

Ocorre quando está ListView em modo virtual e está a decorrer uma pesquisa.

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

Exemplos

O seguinte exemplo de código demonstra a utilização deste elemento. No exemplo, uma pesquisa retorna a correspondência mais próxima a um número inteiro especificado numa lista dos primeiros dez mil quadrados. Este exemplo de código faz parte de um exemplo mais amplo fornecido para a VirtualMode propriedade.

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

Observações

Este evento ocorre quando a ListView está em modo virtual e o FindNearestItem método ou FindItemWithText é chamado. Ao lidar com este evento, deve calcular qual item da lista de itens fornecidos pela Items propriedade corresponde aos critérios de pesquisa e definir a SearchForVirtualItemEventArgs.Index propriedade para o índice do ListViewItem. Se um artigo não for fornecido, FindNearestItem e FindItemWithText irá devolver null.

Para obter mais informações sobre como manipular eventos, consulte Manipulando e gerando eventos.

Aplica-se a