[RadGridView] Unexpected exception when adding ColumnGroups

1 Answer 25 Views
GridView
Arthur
Top achievements
Rank 1
Iron
Iron
Iron
Arthur asked on 09 Dec 2021, 11:32 AM | edited on 09 Dec 2021, 11:59 AM

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!

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 10 Dec 2021, 03:32 PM

Hi Arthur,

Thank you for the detailed description of your issue.

I can confirm that I was able to replicate the exception at my end and have traced it to a bug in the CommonHeaderPresenter class which only removes the first column group from its internal GroupNames HashSet when the RemoveRange method is invoked.

As a thank you for bringing this to our attention, I've awarded you with some Telerik points.

I've gone ahead and applied a fix for this which will be available with our internal build on Monday 20/12. I do hope you find such a time frame suitable. For the time being, you can use the Remove method instead as you've already figured out.

Please let us know once you manage to test the fix.

Regards,
Dilyan Traykov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Arthur
Top achievements
Rank 1
Iron
Iron
Iron
commented on 10 Dec 2021, 03:53 PM

Hi Dilyan,

Thanks for letting me know, 20/12 is fine.
I'll get to you when I have the chance to try it!

Best regards

Dilyan Traykov
Telerik team
commented on 13 Dec 2021, 04:29 PM

I'm glad to hear that you find the proposed time frame suitable. Do inform me once you give the fix a try. I will be awaiting your reply.
Arthur
Top achievements
Rank 1
Iron
Iron
Iron
commented on 20 Dec 2021, 03:50 PM

Hello Dilyan,

How will I know the new version is out, and where to get it?

Thanks!

Dilyan Traykov
Telerik team
commented on 20 Dec 2021, 05:15 PM

The latest internal build containing the fix should already be available from the Downloads page of your Telerik account named "Telerik_UI_for_WPF_2021_3_1220_Dev_Hotfix.zip" under the Internal Builds tab.

Please let me know if you're able to download and use it and whether it resolves the exception at your end.
Tags
GridView
Asked by
Arthur
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dilyan Traykov
Telerik team
Share this question
or