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

Iterate over RadGridView

14 Answers 216 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Saaed Bhatti
Top achievements
Rank 1
Saaed Bhatti asked on 18 Nov 2009, 06:04 PM
How can I iterate over all the rows in a  RadGridView?

14 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 19 Nov 2009, 06:29 AM
Hi,

You can check this demo for more info.

All the best,
Vlad
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
Saaed Bhatti
Top achievements
Rank 1
answered on 19 Nov 2009, 02:05 PM
Thanks.
0
Joe
Top achievements
Rank 1
answered on 07 Dec 2011, 02:15 AM
Where the heck does that demo illustrate how to iterate the rows? why can't you post the answer here? I searched and found RadGridView.Rows but it apparently not existing.
0
Maya
Telerik team
answered on 07 Dec 2011, 07:31 AM
Hello Joe,

Actually, the recommended way is to iterate through the Items collection of the grid. As the virtualization is turned on by default, RadGridView will create only the visible visual elements. That being said, getting all rows will return only those that are in the view port. That is why, you need to work with the Items instead.
 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Joe
Top achievements
Rank 1
answered on 07 Dec 2011, 06:01 PM
thanks.

The problem is that the row selection is lost after paging. I want to keep the previous page's row selection. So I have an array to store the previous page's selection and turn them ito isSelected equal to true after the paging, but if I can not iterate the rowElement, how can I set the row to be selected? something like
I have a list<T> savedSelection
I want to do :
foreach (var rowelement in the RadGridView)
{ if (savedSelection.Contains(rowelement))
      rowelement.isselected = true;
}

how can I do this?
0
Joe
Top achievements
Rank 1
answered on 10 Dec 2011, 02:10 AM
This should be a bug for Telerik!
Items are object, not gridviewRow type, which mean I can not do anything to the Gridview.
0
Maya
Telerik team
answered on 12 Dec 2011, 10:03 AM
Hi Joe,

GridViewRow is the visual element, while those in the Items collection are the data items from the source of the grid. 
The behavior you experience with selection is the expected one since the source of each page is changed on walking back and forth the pages and there is no guarantee that the source of a particular page is exactly the same as it was before when you were on it. What you can try is to save the selected item(s) on each page, handle PageIndexChanging event for example and set again the selected item(s) when you are at the required page.
Another possible approach would be the one illustrated in this forum thread.

 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Joe
Top achievements
Rank 1
answered on 16 Jan 2012, 07:54 PM
I have to maintain  a permanent link which can be shared with other peoples via URL. I set up query strings so everything works perfect except the selected status. I want the other people can continue to work on the selected items by de-selecting or adding more rows. but now there is no way I can set the items in the selectedItems to be on "isSelected" status, which means it won't highlight in the view port. is this by design? or does this make sense to be one of the user scenario?
0
Maya
Telerik team
answered on 17 Jan 2012, 01:18 PM
Hello Joe,

Generally, there should be no problem to add a particular item to the SelectedItems collection of the grid (in case SelectionMode is set to 'Multiple" or "Extended'). However, you need to make sure that this item is available.
Could you provide a bit more details on your scenario - do you still use pager and want to display selected items on navigating through the pages ? Do you try the suggested approach from the forum thread mentioned above ?  

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Joe
Top achievements
Rank 1
answered on 17 Jan 2012, 07:36 PM
Hi Maya,
thanks for the reply.

Yes, I can set the selectedItems, which is not a problem. But even the selectedItems has that row, but that row does not highlight since it is selected. I want all of the seletedItems are highlight as normal after I added them to selectedItems collection.
There are two scenarios for me but they are rooted at one problem:
1. Paging, I want to keep the selectedItem when paging, I can maintain these with my collections and set them during paging, but they are not highlight as selectedItems, in otherwords, users does not know that item is selected since it is not hightlight visually.
2. Sharing with collegues: I created a permlink and shared with people, but again, the selectedItems can be retrieved since I maintain them but they are not highlighted so users have no idea if they are selected, and if they want to continue to work on the selectedItems, there is no way to tell which ones are selected already.

thanks,
Joe
0
Maya
Telerik team
answered on 18 Jan 2012, 04:07 PM
Hi Joe,

Please take a look at this blog post for a reference. Will the approach illustrated there fit into your scenario ?  

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Bryan
Top achievements
Rank 1
answered on 09 Jun 2014, 01:57 PM
Hello, I was looking over the demo that you linked to and couldn't find the "{StaticResource GridViewCellStyle}" That is utilized in Example.xaml. Would you please tell me where I can find this code? I am trying to set the background property of a cell based in the binding. Thanks.
0
Yoan
Telerik team
answered on 09 Jun 2014, 04:56 PM
Hi Bryan,

If you want to style conditionally RadGridView's cells, the way to go is to use CellStyleSelector. You can check this help article for a reference. Moreover, you can check the CellStyleSelector online demo.

As for your other question - the GridViewCellStyle resource is needed since our demos are using the Implict Themes theming mechanism. Basically, when you are using it, you need to base your custom style on the needed control using the name of the control and the suffix “Style” as a StaticResource. You can find detailed instruction on how you can apply a Style together with implicit themes in this help article.


Regards,
Yoan
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Bryan
Top achievements
Rank 1
answered on 09 Jun 2014, 05:56 PM
Thank you, this is exactly what I need.
Tags
GridView
Asked by
Saaed Bhatti
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Saaed Bhatti
Top achievements
Rank 1
Joe
Top achievements
Rank 1
Maya
Telerik team
Bryan
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or