Hi!
I have a feature request, where I have to activate grouping only if the group-operation will result in more than one group. If there will be only one group, I have to display a “flat” list. Is there an easy way how I can achieve such a behaviour?
To provide a little bit more background information.
Best regards,HiCo
Hello Hico,
Thank you for your post.
I have been looking into it. I am not sure that I understand your requirements correctly. If you want to check the number of groups in XamDataGrid, you can handle it`s Loaded event. In the event handler of Loaded you can get the count of current groups by using Count property and access it by RecordManager.Groups collection of XamDataGrid. In order to be able to clear the groups, if their count is equal to one, you can use Clean method of SortedFields collection. I created a short sample application based on your scenario to show you how you can implement the functionality that you are looking for. If the attached sample application does not meet your goals, would you please modify it with the functionality, that you are using. This way I would be able to further investigate your requirements for you and provide you with more detailed information on this matter. Please let me know if I am missing something about your scenario.
Please let me know if you need any further assistance.
Hi Zhivko,thank you for the sample. Unfortunately it did not solve my problem. I changed your sample to reflect my current scenario a little bit better. As you will see in the sample project, the bound data-source will be populated AFTER the Loaded-Event of the DataGrid and furthermore will be changed over time.
My business model “Person” should be grouped by “gender”, but if all entries have the same gender, there should be no grouping. If I add another person with gender set to a different value, a new record should be added and the grouping should be activated.
I would need something like a DataSource-Changed event. I tried SourceUpdated and OnRecordAdded, but the events did not fire - maybe because the “change” is code-triggered.
During the preparation of the attached sample-project, I found another possible solution. I used the RecordsInViewChanged event. If this event fires, I perform an update of the groups. This will only solve my problem partial, since this event will not fire if I change the gender of an existing record. I solved that by applying the workaround from http://ko.infragistics.com/community/forums/t/7569.aspx. That brought me one step closer to the final solution, but one thing is still missing. I am now able to activate the grouping if necessary, but deactivating will not work. In addition to that, the OnValueChanged event will not fire if the record is not in view.
I’m a little bit lost. :)
Best regards HiCo
Hi Zhivko!
Here are my steps for reproducing the problems:
Reproduction of Scenario 1
1. Load Persons (female only) => no grouping2. Change Gender => no grouping, although the last entry has now a different value.
This will work if you do the following:
1. Load Persons (female only) => no grouping2. Scroll to the last entry3. Change Gender => grouping works
Reproduction of Scenario 2
1. Load Persons (female only) => no grouping2. Scroll to the last entry3. Change Gender => grouping works4. Change Gender again => grouping still activated
1. Load Persons (female only) => no grouping2. Scroll to the last entry3. Change Gender => grouping works4. Expand group "Male"5. Change Gender again => grouping deaktivated => Correct
The reason for both problems is the missing ValueChanged-event if the records are not visible.
Best regardsHiCo
Thank you for your feedback.
I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Hi Zhivko,
My described "solutions" are just workarounds and not applicable in our case. The scenarios should work without them. :)
RegardsHiCo
I have been further investigating the behavior that you have describe and it seems that it is expected. It is caused by Virtualization of XamDataGrid, you can read more details about it from the following link from our online documentation:
http://help.infragistics.com/Help/Doc/WPF/2015.1/CLR4.0/html/xamData_Cells_CellValuePresenters_and_Cell_Virtualization.html
That I can suggest is to use the BringRecordIntoView method of XamDataGrid in the event where change the value of gender, so you will bring the record into view and the grid will group the data. Also you should use BeginInvoke method of Dispatcher and call in it UpdateGrouping, so you can achieve the functionality that you are looking for. I modified the last sample application to show you how you can implement this approach.
Please let me know if you need any further assistance on the matter.
I am just checking if my last reply was helpful for you.
If you require any further assistance please do not hesitate to ask.