ListView.SearchForVirtualItem 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生在 ListView 處於虛擬模式,而且已經開始進行搜尋時。
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
事件類型
範例
下列程式碼範例示範如何使用這個成員。 在此範例中,搜尋會將最接近的相符專案傳回前十萬平方清單中的指定整數。 此程式碼範例是提供給 屬性之較大範例的 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
備註
當 處於虛擬模式且呼叫 或 FindItemWithText 方法時 ListView , FindNearestItem 就會發生此事件。 處理此事件時,您應該從 屬性所提供的 Items 專案清單中計算哪些專案符合搜尋準則,並將 屬性設定 SearchForVirtualItemEventArgs.Index 為 的 ListViewItem 索引。 如果未提供專案, FindNearestItem 則會 FindItemWithText 傳回 null
。
如需處理事件的詳細資訊,請參閱 處理和引發事件。