ArgumentException: Cell is not valid when checking if currently edited cell is part of the selection

0 Answers 62 Views
GridView
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Eldoir asked on 07 Jun 2022, 09:11 AM | edited on 07 Jun 2022, 09:11 AM

Hello,
In a behavior on RadGridView I'm subscribing to KeyDownEvent, and when I press Enter, I execute the following code:

I wanted to check what happens if I hit Enter without selecting any cell in the grid.
So first, I click outside the grid, this selects the first cell of the grid in an "unfocused" style:

Then, I hit Enter a first time:  my code hits the first condition (AssociatedObject.SelectedCells.Count == 0) and does the early-return.
It also selects the next cell in the column:

I hit Enter a second time: my code hits the second condition (the one underlined in red), and throws an ArgumentException:

From what I understand, this is raised from CellInfoCollection.Contains, so from code I cannot debug since it's a Telerik dll.
Do you have more info on this? What am I doing wrong?
Thanks!

Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
commented on 07 Jun 2022, 10:24 AM

I've fixed my issue by doing the following instead:

Please let me know if you have a better solution (one that would avoid having a comment explaining Telerik's internal behavior).
Thanks!

Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
commented on 14 Jun 2022, 08:42 AM

EDIT: just noticed I posted this in UI for Silverlight.
Should be in UI for WPF. Sorry!
Dilyan Traykov
Telerik team
commented on 16 Jun 2022, 10:15 AM

The reason for this behavior is that when invoking a Move command (which happens when the Enter key is pressed) which changes the current cell, the newly assigned CurrentCellInfo only has its Item and Column properties set (due to the two-parameter constructor being used). Thus, you can add a check for the Owner property and create a new GridViewCellInfo object only if it is null. Still, your current approach is completely valid and I see nothing wrong with using it if it works for you.
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
commented on 16 Jun 2022, 10:31 AM | edited

Hello Dilyan,

I would have gladly checked for the Owner property on GridViewCellInfo instead of using a .Contains method, but unfortunately, it is private.
Actually, the internal booleans HasItemAndColumn or IsValid would have been perfect for my needs.
Anyway, I used .Contains because I didn't see any other way using the public API!
Thanks for your reply anyway!

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or