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?
9 Answers, 1 is accepted
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,
the Telerik team
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?
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.
the Telerik team
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.
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.
the Telerik team
I was working with the "Q3 2011 SP1" version of the Telerik controls.
When I upgraded to the latest version the problem disappeared.
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.
Dess | Tech Support Engineer, Sr.