>>>Hi All, I'm looking at using the ListView control in virtual mode - I have managed to populate the list by creating a generic List of type ListViewItem , which I populate from a DataTable, then in the RetrieveVirtualItem eventhandler I set the e.Item property to MyList[e.Index] ( which is passed in the eventargs param ), this all works pretty well. The question I have is, what is the best way to search the ListView for a given string ? When in virtual mode the items collection is not available so you have to manage an event called SearchForVirtualItem which is raised whenever you call FindItemWithText("your text"). What I do at present , is, loop through my generic list and compare its' Text property to the Text property in the eventargs of the eventhandler - this doesn't strike me as very efficient. Any ideas ?
>>
>>Linq? :
ListViewItem v = (ListViewItem) (from ListViewItem lvi in MyList where lvi.Text == e.Text select lvi).FirstOrDefault();
>
>Hi Viv, thanks for that , what I need is the index of the ListViewItem - but I can get it from the item - thanks again
int index = (int)(from ListViewItem lvi in MyList where lvi.Text == e.Text select lvi.Index).FirstOrDefault();
(will be 0 if not found)