Iterate over RadGridView

15 posts, 0 answers
  1. Saaed Bhatti
    Saaed Bhatti avatar
    4 posts
    Member since:
    Oct 2012

    Posted 18 Nov 2009 Link to this post

    How can I iterate over all the rows in a  RadGridView?
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 19 Nov 2009 Link to this post

    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.
  3. DevCraft banner
  4. Saaed Bhatti
    Saaed Bhatti avatar
    4 posts
    Member since:
    Oct 2012

    Posted 19 Nov 2009 Link to this post

    Thanks.
  5. Joe
    Joe avatar
    17 posts
    Member since:
    Nov 2011

    Posted 06 Dec 2011 Link to this post

    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.
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 07 Dec 2011 Link to this post

    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 >>

  7. Joe
    Joe avatar
    17 posts
    Member since:
    Nov 2011

    Posted 07 Dec 2011 Link to this post

    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?
  8. Joe
    Joe avatar
    17 posts
    Member since:
    Nov 2011

    Posted 09 Dec 2011 Link to this post

    This should be a bug for Telerik!
    Items are object, not gridviewRow type, which mean I can not do anything to the Gridview.
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 12 Dec 2011 Link to this post

    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 >>

  10. Joe
    Joe avatar
    17 posts
    Member since:
    Nov 2011

    Posted 16 Jan 2012 Link to this post

    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?
  11. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 Jan 2012 Link to this post

    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 >>

  12. Joe
    Joe avatar
    17 posts
    Member since:
    Nov 2011

    Posted 17 Jan 2012 Link to this post

    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
  13. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 18 Jan 2012 Link to this post

    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 >>

  14. Bryan
    Bryan avatar
    2 posts
    Member since:
    Jun 2014

    Posted 09 Jun 2014 in reply to Vlad Link to this post

    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.
  15. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 09 Jun 2014 Link to this post

    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.
     
  16. Bryan
    Bryan avatar
    2 posts
    Member since:
    Jun 2014

    Posted 09 Jun 2014 in reply to Yoan Link to this post

    Thank you, this is exactly what I need.
Back to Top
DevCraft banner