ListView.SearchForVirtualItem Händelse
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Inträffar när ListView är i virtuellt läge och en sökning pågår.
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
Händelsetyp
Exempel
Följande kodexempel visar hur den här medlemmen används. I exemplet returnerar en sökning den närmaste matchningen till ett angivet heltal i en lista över de första tio tusen rutorna. Det här kodexemplet är en del av ett större exempel för egenskapen VirtualMode .
//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
Kommentarer
Den här händelsen inträffar när en ListView är i virtuellt läge och FindNearestItem metoden eller FindItemWithText anropas. När du hanterar den här händelsen bör du beräkna vilket objekt från listan med objekt som tillhandahålls av Items egenskapen matchar sökvillkoren och ange SearchForVirtualItemEventArgs.Index egenskapen till indexet för ListViewItem. Om ett objekt inte har angetts FindNearestItem och FindItemWithText returnerar null.
Mer information om hur du hanterar händelser finns i Hantera och höja händelser.