Hello Team,
I am using XAMDatagrid in WPF. I have used "GroupByPresenter" style to group the records with Checkbox in group row. I am selecting child group records on clicking of checkbox in Header row.
Now I have two issues.
1) I have two level grouping - so want check checkbox of second level group when first level(Main Parent) level group checkbox is checked.
2) When user clicks anywhere in area of group row selection of child rows is removed.
I have attached video to give u better understanding of my problem.
It would be great help if u can provide me a solution.
Thanks & Regards,
Vikram U
I have attache my code in zip file.
Basically second issue is that,
Suppose I have Hierarchy like below
Parent1 - Group Row
SubParent1 - Group Row
Child1.1 - Normal Data row
Child1.2 - Normal Data row
Parent2 - Group Row
SubParent2 - Group Row
Child2.1 - Normal Data row
Child2.2 - Normal Data row
Now If I click On Parent1 checkbox it selects all the child rows under that parent means Child1.1 and Child1.2
Now If I click anywhere in group area or somewhere else in XAm grid it removes the selected rows (Child1.1, Child 1.2)
I haven't tried your code will do and let u know the result.
Thanks,
Vikram
Hello Vikram,
I have created a sample project based on the relevant styles and code-behind that you have provided. The reason that you are seeing the deselection behavior that you are is due to a mix between the inability to select records from different layouts, and the fact that the GroupByRecords can be selected by clicking on them. There are a couple of points in the code that you have provided that could have this effect.
First, in the MouseLeftButtonDown event handler for your MySTACK StackPanel, you are not marking this event as handled, and so it will bubble up to the GroupByRecordPresenter and fire its record selection code. So, if you click on the GroupByRecordPresenter, it will expand, try to select the child records that belong to it, and then the event will bubble out and select the GroupByRecord, which will deselect your child records. I would recommend setting the e.Handled property on this event to "True" to prevent this, where e is the event arguments.
The order of selection in the SetSelectionChild method is doing something very similar to the above, where the selection order seems to be happening along the lines of DataRecords => GroupByRecord => DataRecords. If you only have a single GroupByRecord in the child grouping band, this is fine, but with multiple, it will only work for the last set of DataRecords due to the layout selection issue mentioned above. If would recommend making a check in your SetSelectionChild method to prevent the selection from happening if your "rec" variable is a GroupByRecord.
I have attached a sample project to demonstrate the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hello Andrew,
Thanks for the response. Now you have sent different code in different projects for both the solution.
In your first reply "XDGGroupBySelectionCase" only first solution is given and in second reply "XDGTest" only second solution is given.
I want to know DO I need to combine both the code and if yes then how?
Or Both the solutions are not possible?
Regards,
Personally, my recommendation here would be to continue with the XDGGroupBySelectionCase project, as in the XDGTest one and the sample code that you had provided me, the Checkboxes do not have their IsChecked property bound to anything, and this may cause issues when scrolling the grid due to the virtualization.
It seems that the only real modifications that would need to be made to the XDGGroupBySelectionCase solution is that you would need to modify the Style and Behavior such that you detect the click on a StackPanel in the GroupByRecordPresenter rather than just the Checkbox. You would also need to expand the group-by records, but other than that, all of the functionality that you are looking for appears to be there already.
To continue with XDGTest would be rather difficult due to the lack of binding of the Checkbox's IsChecked property to anything related to the underlying GroupByRecord, and quite a bit would need to be changed in this project, as you may have difficulties finding the child-level GroupByRecordPresenters and their containing Checkboxes for the recursions to check or uncheck all of the sibling group records, as they will be virtualized and may return null when you try to retrieve them. By going the binding way in the XDGGroupBySelectionCase, you can modify the Checkboxes through the GroupByRecord rather than its presenter, which will always be there as long as your grid is grouped.
When I implemented grid I found one issue. When we assign datacontext on constructor of the form like "MainWindow" It unchecks sub groups checkboxes on load.
But if I assign datacontext on any other event then it does not uncheck subgroups and clicking on checkbox of subgroup it throws error.
I have attached screenshots for the same and code file.
Please clarify your issue and expected behavior. Do you mean that you want certain checkboxes selected by default and they are not when assigning the datacontext in the window's constructor? Note, I was not able to reproduce the error you've reported after trying to incorporate your code with Andrew's sample. Please note that I expect for the checkboxes to be unchecked if the datacontext has been reassigned. In Andrew G's latest sample no checkboxes are checked upon loading the data.
Let me know if you have any questions regarding this matter.