RadGridView CollectionChanged Event

5 posts, 0 answers
  1. Nirav
    Nirav avatar
    3 posts
    Member since:
    Nov 2015

    Posted 02 Nov 2015 Link to this post

    Hi,

    Our code is using WPF with MVVM pattern. We are using the RadGridView to display the users data in rows with check box option to select/deselect all rows.

    In my code I have a class which derives from 

    Behavior<RadGridView>

    and inside I have 

    target.AssociatedObject.SelectedItems.CollectionChanged += target.GridSelectedItems_CollectionChanged;
    where target is ​Behavior<RadGridView>

    My WPF code related to grid is: 

    <telerik:RadGridView x:Name="Users" HorizontalAlignment="Stretch" AutoGenerateColumns="False" ShowColumnFooters="True"  SelectionMode="Extended"><telerik:RadGridView x:Name="Users"Stretch" AutoGenerateColumns="False" ShowColumnFooters="True" SelectionMode="Extended">​

    Issue:

    When I select all using the top most checkbox in the grid - the event 

    GridSelectedItems_CollectionChanged

    fires for every item getting selected. So, if grid have 5 users in the grid - the event fires 5 times for selection/deselection of contacts.

     I think collection changed method should fire only one time.

     

    Any clarification on this would be appreciated.

    Thanks,

    Nirav Patel

  2. Stefan X1
    Admin
    Stefan X1 avatar
    517 posts

    Posted 04 Nov 2015 Link to this post

    Hi Nirav,

    The recommended approach for such scenarios is to use the SelectionChanged event of RadGridView. Would it be possible for you to share some details on what you are trying to achieve? Is there a specific requirement to handle the CollectionChanged event of the SelectedItems collection, instead of SelectionChanged?

    Best Regards,
    Stefan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nirav
    Nirav avatar
    3 posts
    Member since:
    Nov 2015

    Posted 09 Nov 2015 in reply to Stefan X1 Link to this post

    Thanks Stefan for the reply. My apologies for the late reply.

     I am using the code mentioned in the blog http://www.telerik.com/blogs/how-to-synchronize-your-ui-selected-items-with-your-data-context-using-mvvm-and-blend-behaviors-for-silverlight-and-wpf

    It has the SelectedItems.CollectionChanged in it.
  5. Stefan X1
    Admin
    Stefan X1 avatar
    517 posts

    Posted 11 Nov 2015 Link to this post

    Hello Nirav,

    Thank you for this clarification.

    However, for a scenario as yours in which you depend on the selection, as suggested in my previous post, I recommend you using the SelectionChanged event of the control.

    Regards,
    Stefan X1
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Nirav
    Nirav avatar
    3 posts
    Member since:
    Nov 2015

    Posted 11 Nov 2015 in reply to Stefan X1 Link to this post

    Thanks Stefan for the update. I'll implement as suggested.
Back to Top
UI for WPF is Visual Studio 2017 Ready