[英]C#: How do you make it so that you can decide which items you want specifically draw into a listview in virtual mode?
在虛擬模式下如何僅繪制某些ListView項目的精確副本? 來自相同名稱,不同帳戶。
@喬納森:請加強您的問題,而不要輸入新副本。
我正在嘗試將過濾器機制實現為listview對象(在虛擬模式下)。 我得到了一些建議,不要在我不想顯示的retrieve_item事件中不返回有問題的項目,但是當我不返回小於列表視圖項目的任何內容時(從保存有所有有問題的列表視圖項目的列表視圖項目緩存),我得到一個異常錯誤,說我必須在RetrieveVirtualItem事件中返回一個有效的ListViewItem,就像它在msdn中讀取的那樣。
來源: http : //msdn.microsoft.com/en-us/library/system.windows.forms.listview.retrievevirtualitem.aspx
因此,當我叫出自己的方法之一時,我該如何僅決定像[view] [25]這樣的列表中顯示的項目[0],[5]和[11] ?
使用所需的過濾器完成任務后,我想將所有原始項目還原到列表視圖中,我該如何實現這樣的功能?
// Initialized with 25 listviewitem & subitems objects later during the programs runtime.
public ListViewItem[] lviCache;
private void lvListView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
e.Item = lviCache[e.ItemIndex];
}
void UnfilterlvItems()
{
// How would I revert it back so that it draws all original items
// from my listviewitem[] array back to normal to display
// all 25 objects again?
}
void FilterlvItems()
{
// What would I be putting in here so that I can fire off the
// retrievevirtualitem events and only decide which items I want
// display for the time being? {0, 5, 11 }
}
您需要這樣做:
filteredItems
。 在您的示例中[0, 5, 11]
該外觀類似於[0, 5, 11]
resultsList.VirtualListSize = filteredItems.Count;
在RetrieveVirtualItem
,從數組中返回該項目:
return lviCache[filteredItems[ev.ItemIndex]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.