The issues we can reproduce with the latest version 2016.2.822.40
Issues #1 and #2.
How to reproduce on the test project:
Run the application.
Click the «Create new QCV with group descriptor» button.
See pic. 1
We see two issues:
1. Groups inside the table are doubled. Group descriptors collection
contains two group descriptors (of the same type: GroupDescriptor), but only
one is shown in «Grouped by» section.
2. Grid itself does not notify when its GroupDescriptors collection has
been changed, though QueryableCollectionView bound to this Grid notifies of its
GroupDescriptors collection successfully.
Issue #3
How to reproduce on the test project:
Start the application.
Delete the «Profession» group descriptor (click on X in «Groupped by»).
Group by the «Profession» group manually (drag-and-drop column header onto «Grouped by»).
Click the «Create new QCV with group descriptor» button.
See pic. 2.
We see now, that group descriptors were
doubled. In the GroupDescriptors collection of Grid there are two descriptors
of two different types: ColumnGroupDescriptor and GroupDescriptor. And it seems
impossible to programmatically add a descriptor of type «ColumnGroupDescriptor»
in the viewmodel, because it should know about the UI (it needs column data),
and hence is against the principles of MVVM.
Furthermore, if you now click the «Create new QCV with group descriptor» button again, you will see that groups are tripled:
See pic. 3
6 Answers, 1 is accepted
I will need some time to investigate this issue but, for the time being, this undesired behavior can be avoided by simply calling the Clear method of the QCV's GroupDescriptorCollection before or immediately after creating the new QCV instance.
DataCollection.GroupDescriptors.Clear();
DataCollection =
new
QueryableCollectionView(
new
List<DataModel>
{
new
DataModel {Name =
"Xxx"
, Surname =
"Yyy"
, Profession =
"Programmer"
},
new
DataModel {Name =
"Vasily"
, Surname =
"Bogatov"
, Profession =
"Manager"
},
new
DataModel {Name =
"Borat"
, Surname =
"Petrov"
, Profession =
"Manager"
},
new
DataModel {Name =
"Roman"
, Surname =
"Ivanov"
, Profession =
"Manager"
},
new
DataModel {Name =
"Alex"
, Surname =
"Petrov"
, Profession =
"Manager"
},
new
DataModel {Name =
"Roman"
, Surname =
"Petrov"
, Profession =
"Programmer"
},
new
DataModel {Name =
"Alex"
, Surname =
"Bogatov"
, Profession =
"Programmer"
}
});
Log +=
"Created new QCV"
+ Environment.NewLine;
Another approach would be to check whether the GroupDescriptors collection already contains a GroupDescriptor with the same Member before adding a new one:
private
void
AddGroupDescriptor(
string
name)
{
var groupDesciptor =
new
GroupDescriptor { Member = name };
if
(!DataCollection.GroupDescriptors.Where(x => x
is
GroupDescriptor).Any(x => (x
as
GroupDescriptor).Member == name))
{
DataCollection.GroupDescriptors.Add(groupDesciptor);
Log +=
string
.Format(
"Added group decriptor '{0}' to initial QCV."
+ Environment.NewLine, name);
}
}
Please let me know if any of these approaches would work for you. If that is not the case, please provide more details about your exact requirements and I will gladly assist you further in finding a solution for your particular scenario.
Regards,
Dilyan Traykov
Telerik by Progress
Hello Dilyan! Thanks for your response.
Unfortunately, these approaches do not satisfy us.
First, the approach with clearing group descriptors collection before creating
a new object seems like a workaround.
Second, in our projects we use a lot of custom behaviors for grids. They rely
on grid’s events, and one of the main issues now is that grid doesn’t raise the *CollectionChanged* event after its
GroupDescriptors collection has been changed, as described and show above
(issue #2).
Third, usage of an additional external comparer for group descriptors seems
like a rude workaround for us, since RadGridView (as we can tell from its source code) has its own comparator for group
descriptors, and it seems to work somehow improperly.
The issue you're observing is due to the fact that when creating the new QCV and setting it as RadGridView's ItemsSource, the grid already has a group descriptor in its GroupDescriptors collection and tries to synchronize its Items collection (with its GroupDescriptor) and the new QCV.
At this point, the new DataItemCollection (the Items collection) has one group descriptor and when you call the AddGroupDescriptor method, internally no check is made if the current descriptor is already in the collection. This can be observed if you manually add the same descriptor (through a button click, for example) multiple times.
Modifying this behavior, however, would be a breaking change, and thus the better solution, in this case, would be to let the developer decide whether or not he wants to have duplicate group descriptors.
Thus, the recommended approach in this situation would be to manually check whether the current group descriptor should be added or not.
I hope that you find this information helpful and that this suggested approach would work for you. Please let me know whether this is the case.
Regards,
Dilyan Traykov
Telerik by Progress
Thank you for the answer.
It still seems a bit strange that Grid cannot see when two group descriptors are identical on the synchronization step (after its ItemsSource has been changed), and tries to keep both of them. And pretty strange that only one of them is displayed in the corresponding section of the grid, though both of them are used to actually group data.
Anyhow, it seems that we can use that workaround and filter group descriptors by our own. But there is still an issue here: as described above (Issue #2), Grid doesn’t raise the CollectionChanged event after its GroupDescriptors collection has been changed.
Can you comment on this, please?
Actually, in this case (Issue #2), RadGridView has a single group descriptor - thus the CollectionChanged of RadGridView's GroupDescriptors collection is fired only once. The QCV's GroupDescriptors collection, on the other hand, has 2 group descriptors, but at this point (after adding the group descriptor to the new QCV), in the synchronization step, RadGridView actually does compare descriptors with the GroupDescriptorEqualityComparer, which takes into account the Member property, and thus, no additional descriptors are added to its collection. That is the reason only a single "Grouped by" header is displayed in the grid's GroupPanel.
I do understand that this behavior may seem a little ambiguous and the points you made in your previous reply are nothing but valid, but since it would be a breaking change for our customers to modify this behavior, I'm afraid that for the time being, we cannot commit to changing it.
I hope this clarifies things up for you. Do let me know if any other questions or concerns arise.
Regards,
Dilyan Traykov
Telerik by Progress