This is a migrated thread and some comments may be shown as answers.

[Solved] optimized method for determining if a RadGrid, RadList or RadTreeview has a selected item in it

3 Answers 85 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Albert Shenker asked on 09 Sep 2009, 05:52 PM
If I want to determine whether a particular Rad Grid, Rad List  or RadTreeview has an item which is selected (or checked node in the case of Rad TReeview), I can use the inherent selectedItems or checkednodes properties that these controls expose. However, to determine if a single item is selected, it is not necessery to return all the selected items. Therefore it would seem to me, that a more efficient method of determining whether an item is selected is to loop through all the items and if you come across one which is selected, return true (ie exit the loop) This would be the case unless Telerik used some sort of optimization technique for storing the selecteditems collection without looping through the entire set to setermine it. So, my questions is, does this kind of optimization exists, or is my method of looping instead of using the inherent selecteditems collection a more optimized way of determining whether an item has been selected.

On a related note, is there a way to get a list of all the nodes in a treeveiw without actually traversing the tree in a recursive fashion (ie is there some sort of optimized method of obtaining the full node list)

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 15 Sep 2009, 02:31 PM
Hi Albert,

You can check directly whether the SelectedItems or SelectedIndexes collection of the grid is non-empty - if so, this means that these is a selected item in the control.

Regarding your treeview and listbox questions:

RadListBox keeps a list of the indexes of the selected items. Therefore the SelectedItem and SelectedItems collection are created based on these selected indexes.

RadTreeView exposes a SelectedNodes collection which uses the GetAllNodes method to check the selected state of each node. The SelectedNode property gets the first element of the collection.

Greetings,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 15 Sep 2009, 02:50 PM
so if I understand correctly, in the case of and Rad Grid, Rad List, I can use the selecteditems collection, and this is the fastest way to determine if an item is selected. However, in the case of Rad Tree, since it uses GetAllNodes, it would be faster to loop through myself and exit the loop when I encounter a selected node.

0
Veselin Vasilev
Telerik team
answered on 15 Sep 2009, 03:36 PM
Hi Albert Shenker,

Yes, that is correct.

Greetings,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Answers by
Veselin Vasilev
Telerik team
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Share this question
or