Hi,
I'm adding 2 column groups to my RadGridView, say "A" and "B".
Then I'm removing them using myRadGridView.RemoveRange().
Then I try to add them again: it works for "A", but raises an exception for "B": InvalidOperationException, because apparently a column group with this name already exists.
But I had removed "B" from the column groups!
So I tried to repro with a very simple case:
var cg = new GridViewColumnGroup { Name = "test" };
myRadGridView.ColumnGroups.Add(cg);
myRadGridView.ColumnGroups.Add(cg);
This is done right at the start of the app.
I exepect this to raise the same exception, since I'm trying to add several column groups with the same name.
But it executes without any problem!
So how does it work internally? At the moment this doesn't make much sense to me...
I'm wondering if this exception is only raised if the column groups are actually used by some columns, that are bound to data, but I can't tell...
Thanks for your feedback!
EDIT: I noticed the event RadGridView.ColumnGroups.CollectionChanging is only fired when using ColumnGroups.Add or .Remove, but not when using ColumnGroups.AddRange or ColumnGroups.RemoveRange. Could this be related to my issue?
EDIT2: I managed to avoid the exception by looping through my groupsToRemove and calling .Remove for each of them, instead of directly calling .RemoveRange. This is in the docs: WPF DataGrid | Column Groups | Telerik UI for WPF. However, I'm not using .SuspendNotifications() and .ResumeNotifications() around my loop. If I do this, the exception is raised again. Hope this helps!