RadGridView - Hierarchy - Selected Parents and Childs

8 posts, 0 answers
  1. Xavier
    Xavier avatar
    3 posts
    Member since:
    Jul 2012

    Posted 16 Feb 2011 Link to this post

    Hello,

    I'm trying to build a grid with a customized Hierarchy like in the example in the help.
    http://www.telerik.com/help/wpf/images/RadGridView-CustomHierarchies-1.png

    My requirements :

    - I want to be able to select one/many parents (example on the picture : Maria Anders, Antonio Moreno)
    - I want to be able to select one/many children (example on the picture : Id 74784, Id 74719)


    My grid has got already the SelectionMode set to Extended but I'm not able to get more than one child selected.
    My grid.SelectedItems returns only the parent(s) selected. Is there a way to get selected rows of the whole grid ?

    Thanks for your answer.

    Kind regards,

    Xavier

  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 17 Feb 2011 Link to this post

    Hello Xavier,

    Setting SelectionMode to Extended in such scenario will only affect the master grid - the child ones would still have the default SelectionMode. In order to set properties to the child grid you should use ChierarchyChildTemplate as demonstrates here. Using this you can easily change the SelectionMode of the child grids. this will allow you to select multiple items on the master grid as well as on the child grids.

    Currently the child grids are totally disconnected from their parent in terms of selection - every child grid has a separate selection which does not affect the selection of the master grid. Nevertheless it is possible to get the selected items of a child grid but it would be great if we can have more detailed information about our scenario so that we can provide the best approach for this particular scenario.



    Regards,
    Milan
    the Telerik team
  3. UI for WPF is Visual Studio 2017 Ready
  4. Vivek
    Vivek avatar
    33 posts
    Member since:
    Oct 2012

    Posted 17 Sep 2014 Link to this post

    Hi Milan,

    I am also having a scenario where i need to select multiple items in Parent and Child grids, but i need the selection among the parent and child grids to be connected i.e., if i select an item in child grid and select another item from the parent with CTRL key, i want to get both of them selected and when i select another item on the parent later without CTRL key down, i want the previously selected items in the child grids to be deselected. In simple terms, I want the selection among the parent and child grids to behave like how the selection happens in a single grid. Can you suggest me the way on how to do this?

    Thanks,
    Vivek.
  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 22 Sep 2014 Link to this post

    Hi Vivek,


    Thank you for contacting us. 

    Interesting topic to discuss indeed.

    Selection feature of RadGridView could be extended in various scenarios based on specific requirements.

    Since all child grid components are separate elements, there is no straight-forward way to synchronize the selected items in parent and child RadGridView components. 

    Any attempt to alter this logic could lead to many undesired effects in the default behavior of this component. 

    You could try to play with the SelectionChanged event to emulate this behavior however we might not guarantee what would be the final result. 


    Regards,
    Vanya Pavlova
    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.
     
  6. Vivek
    Vivek avatar
    33 posts
    Member since:
    Oct 2012

    Posted 22 Sep 2014 in reply to Vanya Pavlova Link to this post

    Hi Vanya,

    I tried using the SelectionChanged event and i am able to select the items across the grids. I also need the multi select behavior and i made it work for CTRL key by not deselecting items already selected when CTRL key is down, but the problem is with SHFT key, when I click shift+Down, the selection works perfectly within a grid, but when we try to move between the grids i.e., if i click down arrow key from the last item of the child grid, the selection doesn't move over to the next row which is a part of parent grid. Could you suggest me a way on resolving this?

    Regards,
    Vivek
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Sep 2014 Link to this post

    Hi Vivek,

    I am glad to hear you managed to achieve most of the desired functionality.

    As I understand your last requirement would be to be able to start an extended selection from within a details RadGridView and continue with it in the parent RadGridView.

    As the user holds the Shift key and presses the Down arrow key, there are two commands RadGridView executes internally. They are
    1. "Move down"
    2. "Extends selection to current unit".

    I am afraid there is not a command available in RadGridViewCommands to manage an action going back to the parent RadGridView and continuing the selection from the item right after the current parent row. Still, I can suggest you a possible workaround. For the purpose you will need to define your own custom keyboard provider. That way you will be able to redefine the way RadGridView internally handles the operations. You can  refer to our online documentation for further details and also find some sample code. As a side note, you can also check this GitHub example on CustomKeyboardCommandProvider. It demonstrates how to predefine the default KeyboardProvider. 

    I prepared a sample project to illustrate how you could achieve your goal. Basically I find the parent RadGridView, I set its CurrentCellInfo and then I define what RadGridViewCommands to be executed for it. You can find it attached.

    Would you please check it and let me know how does it work for you?

    Regards,
    Dimitrina
    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.
     
  8. Vivek
    Vivek avatar
    33 posts
    Member since:
    Oct 2012

    Posted 06 Oct 2014 in reply to Dimitrina Link to this post

    Thanks Dimitrina, I have defined a custom keyboard provider as mentioned and I'm able to extend my selection with SHFT + Down key. There is another tricky part which I want to achieve here i.e., I already have an item selected in one of the child grids and now i select an item from parent grid by holding the SHFT key (and vice-versa), then all the items between them should be selected. Can you suggest me a way for this too?

    Thanks,
    Vivek
  9. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Oct 2014 Link to this post

    Hi Vivek,

    This is indeed tricky as you need to be aware of
    - which is the item the user just clicked on the details RadGridView
    - which is the parent row of the row details the user was selecting for a last time
    - which is the item the user just clicks on the parent RadGridView.

    Then you need to have their indexes in the respective RadGridView so that you can select the items you wish to. Having this information you can iterate on the items below or after the selected item in the details RadGridView and add them to the SelectedItems collection of the grid needed.

    For the purpose you can subscribe for the SelectionChanged event and implement some additional logic. Please note that you need to subscribe for the SelectionChanged event of the parent RadGridView only. It will be raised when the user selects in both the parent or the details grids and you can distinguish which one raised the event through exploring the e.OriginalSource value available in the event's arguments.

    I extended the demo solution I previously sent to illustrate my suggestion. You can consider implementing some logic similarly.

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready