I am getting the following exception from the grid and cannot understand why. The collection supplied to the function is definitely not empty and my function exits without a throw. Is there a way to understand why the code inside the grid is throwing an error? Then the circuit crashes and the blazor application is now dead.
If I use a GridCommandColumn no errors are raised.
6 Answers, 1 is accepted
Could you try comparing with this sample to see what's the difference causing this: https://docs.telerik.com/blazor-ui/components/grid/selection/single#selecteditemschanged-event?
The stack trace points to accessing the grid's Column collection, so if I have to guess, I'd say that there is something going wrong there - for example, the columns are built dynamically in a foreach loop and when the event happens, the grid has to repaint, but the data for the loop is changed or no longer there, which throws the error.
If this does not help you resolve it, please post here a modified version of the snippet from the documentation that shows the error so I can take a look.
I have refactored the application to use a ShellComponent that uses properties for the its children and I still get the error.The list is not destroyed when the component is "swapped" out as I have a persistent ViewModel for the ShellComponent. However, I do use RenderFragments and am wondering if I have stumbled on to a LifeCycle issue here.
As long as I dont "navigate" for the RouterComponent everything works fine. But if I "navigate" to the required page,the error is triggered - so its something about destroying a component hosting the grid. Hope this example make sense and helps us identify just where the problem is:
- Issue with my understanding of RenderFragment
- Issue with the Grid on dispose inside a RenderFragment Template
- Issue with the way the Lifecycle events are called within this sample
So inside my MVC page I use this to initialise the blazor app:
That application shell razor syntax looks like this:
The CrudComponentRouter markup looks as such:
My Search Component has this grid definition:
I am attaching here two samples I built on top of this code - one is a real server-side blazor app, the other uses the same razor components in an MVC view. Both seem to work fine for me and I suggest you try comparing against them to see what is the difference causing trouble. If this does not help you resolve this, please modify either of them to showcase the issue so I can review it too.
Hello again Wayne,
We had another report that the same error was caused by hiding the grid from within its SelectedItemsChanged handler, you can see if this is your case here: https://feedback.telerik.com/blazor/1456628-system-argumentoutofrangeexception-index-was-out-of-range-when-hiding-a-grid-from-its-selecteditemschanged-handler
Was about to test this but yes, technically my code will hide the grid on the GridRowSelect callback. The reason mine hides is the switch() in my router component. So I would have to agree my issue is exactly the same problem, albeit, triggered a different way.
I just removed the switch statement in my router (matching your example code) and can verify that the problem has gone away. So the two issues can be merged as they are the same problem.