Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ListView in Virtual mode
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01507445
Message ID:
01507899
Vues:
25
>>>>>>>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)

>>>>
>>>>0? If that's the case, how can you distinquish an index to the first item from one that's not found?
>>>
>>>Duh. It's picking up the default int. Maybe:
int index = MyList.Where(i => i.Text == e.Text).Select(i => i.Index).DefaultIfEmpty(-999).FirstOrDefault();
but at that point it's not much of an improvement on the original
>>
>>Hi Viv, thanks for your replies - I've tried
>>
>>
>>int index = (int)(from ListViewItem lvi in MyList where lvi.Text == e.Text select lvi.Index).FirstOrDefault();
>>
>>
>>but for some reason it doesn't work consistently - it finds the first item I search for but fails to find others I know are in the list - if I re-search the original item then look for another one - it *sometimes* finds it but not always. What I've found always works is this
>>
>>
>>e.Index = MyList.FindIndex(i => i.Text == e.Text);
>>
>>
>>Any ideas as to why this is happening ? Thanks again for your help
>
>Can't see why one would return a different result to the other. IAC, if .FindIndex() works then it's a simpler solution (I overlooked the existence of the predicate override :-{ )
>
>Maybe the problem is related to the interaction when SearchForVirtualItem is called. I see that the SearchForVirtualItemEventArgs includes additional properties such as .Direction and .StartingPoint which should probably be taken into account when setting the index. But that still wouldn't explain why .FindIndex() works better .....


I will play around with Direction and StartingPoint when I have time - thanks again
Regards,
Peter J. Kane



Pete
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform