Multi select in hierarchical grid

10 posts, 1 answers
  1. Wesley
    Wesley avatar
    16 posts
    Member since:
    Jul 2012

    Posted 18 Jun 2012 Link to this post


    Hi,

    I'm having some troubles to achieve the multiselect behavior I want in an hierarchical grid
    The behavior I want:
    • When a parent row is selected, all the child rows get selected automatically
    • When at least 1 child row is selected, the parent row gets selected automatically
    • When I 'ctrl-click' on a selected child row, the row gets deselected
    • When a parent row gets deselected, all the child rows get deselected automatically

    I tried implementing this behavior using the "SelectionChanged" and "CurrentRowChanged" events, but did not succeed.

    Even without programmatically setting the "IsSelected" status of rows, it seems that the grid has problems remembering the "IsSelected" status of child rows. For example, when I select 3 of 5 child rows of a certain parent row and then select another parent row, 1 of the 3 selected rows get deselected. I should expect all the child rows to get deselected or all the child rows to stay selected.

    Can you show me how I can achieve the wanted behavior?

  2. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 21 Jun 2012 Link to this post

    Hello Wesley,

    Thank you for contacting us.

    One way to implement the desired behavior is to create custom classes that inherit GridViewDataRowInfo and GridViewHierarchyRowInfo and override their OnPropertyChanging method. In this way you will be able to track the changes in the selection and update the rows IsSelected property accordingly. For implementation details please refer to the attached sample project.

    I hope this helps. Let me know if you have further questions.

    All the best,
    Boryana
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. Wesley
    Wesley avatar
    16 posts
    Member since:
    Jul 2012

    Posted 21 Jun 2012 Link to this post

    Thanks Boryana, worked like a charm!
  4. Wesley
    Wesley avatar
    16 posts
    Member since:
    Jul 2012

    Posted 22 Jun 2012 Link to this post

    Hi,

    After some testing we came accross 2 issues:

    1. It seems that if you use shift+arrow to select multiple rows, the behavior is not right (parent gets deseleted).
    We noticed that the PropertyChanged event on the property "IsSelected" is not triggered when you use shift + arrow. Is there a way around this?

    2. Also we had to write some 'ugly' code to keep the grid from selecting the first row automatically when its datasource is set. What is the best and cleanest way to override the default behavior?
  5. Answer
    Svett
    Admin
    Svett avatar
    728 posts

    Posted 27 Jun 2012 Link to this post

    Hello Wesley,

    I am enclosing a modified version of the project that my colleague previously provided. I replaced the usage of the PropertyChanging event with another method that occurs in all cases. Regarding the clearing of the current row, you can simply set it to null.

    I hope this helps.

    Regards,
    Svett
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  6. Wesley
    Wesley avatar
    16 posts
    Member since:
    Jul 2012

    Posted 03 Jul 2012 Link to this post

    Hi svett,

    That helped indeed. Shift + arrow is working now.

    There is however another issue:
    When I select 3 child rows using shift + arrow (or ctrl + click) they get selected allong with their parent as it should. But if you then click on a non-selected child row, the 3 selected child rows should be deselected. It seems that one of the 3 child rows stays selected. If you then scroll the child rows out and into view, the wrongly selected child row is rendered deselected.
    I suspect that the state of the child rows is always correct, but they are not rendered correctly sometimes.
  7. Svett
    Admin
    Svett avatar
    728 posts

    Posted 05 Jul 2012 Link to this post

    Hello Wesley,

    I did not manage to reproduce the issue. I am enclosing a sample video that demonstrate my attempt. Could you let me know what I missed? Please note that you need web browser and installed flash plugin to play the video.

    Regards,
    Svett
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  8. Wesley
    Wesley avatar
    16 posts
    Member since:
    Jul 2012

    Posted 05 Jul 2012 Link to this post

    Hi Svett,

    I was working with the "Q3 2011 SP1" version of the Telerik controls.
    When I upgraded to  the latest version the problem disappeared.

    Thanks
  9. subista
    subista avatar
    1 posts
    Member since:
    Sep 2018

    Posted 26 Nov 2018 in reply to Wesley Link to this post

    how to select the child row but deselect the parent row?
  10. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3948 posts

    Posted 26 Nov 2018 Link to this post

    Hello, Subista,   

    In order to select rows programmatically I would recommend you to have a look at the following help article: https://docs.telerik.com/devtools/winforms/gridview/selection/selecting-rows-and-cells-programmatically

    In case of hierarchy, you can access the desired child row from the ChildRows collection of each parent row.

    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top