I have a rad grid bound to a collection of custom objects and occasionally I grab a rows index like this:
e.Item.ItemIndexHierarchical
at some point later when I want to retrieve that item (if it still exists) I use this:
gvAgendaItems.Items(HierarchicalIndexKey)
The problem is that sometimes the item doesn’t exist anymore – and I’m OK with that – but I’d like to gracefully skip over the section of code that is working on the items it can find. As it stands, searching for an item using a no longer valid key throws an exception so I can’t just check if the resulting item is nothing.
How can I test if that HierarchicalIndexKey is still valid without throwing an exception?
I don’t see any elegant ways to do this in the Telerik documentation (leaving only blunt/inefficient ways, unfortunately).
You could loop through the items and match the
HierarchicalIndexKeyon each item’sItemIndexHierarchical:You could wrap it in a
Try/Catchblock and simply fail silently.Looping will be more efficient with smaller datasources, where as wrapping will be more efficient with larger datasources (the breakpoint is when it takes more time to loop through the collection than it does to throw an exception).
Wish I had a better answer, but I hope this helps.