This is a migrated thread and some comments may be shown as answers.

Multi select in hierarchical grid

9 Answers 89 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Wesley
Top achievements
Rank 1
Wesley asked on 18 Jun 2012, 02:22 PM

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?

9 Answers, 1 is accepted

Sort by
0
Boryana
Telerik team
answered on 21 Jun 2012, 08:11 AM
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 >>
0
Wesley
Top achievements
Rank 1
answered on 21 Jun 2012, 10:00 AM
Thanks Boryana, worked like a charm!
0
Wesley
Top achievements
Rank 1
answered on 22 Jun 2012, 12:41 PM
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?
0
Accepted
Svett
Telerik team
answered on 27 Jun 2012, 10:44 AM
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 >>
0
Wesley
Top achievements
Rank 1
answered on 03 Jul 2012, 06:55 AM
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.
0
Svett
Telerik team
answered on 05 Jul 2012, 06:51 AM
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 >>
0
Wesley
Top achievements
Rank 1
answered on 05 Jul 2012, 08:25 AM
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
0
subista
Top achievements
Rank 1
answered on 26 Nov 2018, 06:24 AM
how to select the child row but deselect the parent row?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Nov 2018, 09:44 AM
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.
Tags
GridView
Asked by
Wesley
Top achievements
Rank 1
Answers by
Boryana
Telerik team
Wesley
Top achievements
Rank 1
Svett
Telerik team
subista
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or