This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, We are experiencing an exception within WpfDataGrid 5.1 when using hierarchical binding. This exception is difficult to replicate but it seems to occur when either we are expanding a row to display its child rows or quickly scrolling through the grid. We are adding child items to the bound data source after the grid has been loaded, which may be related to the issue. I have tried the latest build (26/06/13 - 5.1.2090) and it still occurs. "System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index\r\n at System.Collections.Generic.List`1.get_Item(Int32 index)\r\n at Mindscape.WpfElements.WpfDataGrid.DataGridItemsSource.#mcb(Int32 index)\r\n at Mindscape.WpfElements.WpfDataGrid.DataGridPanel.MeasureOverride(Size availableSize)\r\n at System.Windows.FrameworkElement.MeasureCore(Size availableSize)\r\n at System.Windows.UIElement.Measure(Size availableSize)\r\n at System.Windows.ContextLayoutManager.UpdateLayout()\r\n at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)\r\n at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()\r\n at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)\r\n at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)\r\n at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)\r\n at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)" Thanks Chris |
|
|
Hello Chris It will take some time to reproduce this problem at our end. Are you also removing items while the DataGrid is in use? Jason Fauchelle |
|
|
Hi Jason, Yes, we are also removing items but we can cause the exception just by adding items. Regards Chris |
|
|
Hi Jason Did you manage to find the cause of this issue? Thanks Chris |
|
|
Hello Chris I have not been able to find this issue yet, it is proving to be difficult to reproduce. I have not yet seen the exception even once. By looking through the stack trace, I know which method the error is occurring in, but I'm not yet sure how the wrong index could be passed in. I will be continuing to look into it this week though. Jason Fauchelle |
|
|
Hello Chris The only way I've been able to reproduce this so far is by setting the FrozenRowCount to be negative. Could this possibly be what's happening in your application? If so, this will be resolved in the next nightly build. If this is not the case, please install the next nightly build and try reproduce the issue again. I've put some better exception messages at the point where the exception is being raised. Send me the message so I can get a better idea of what is happening. Some other questions that may help resolve the issue:
Ideally, if you could send a repro project, this would greatly help debug this issue. Jason Fauchelle |
|
|
Hi Jason The latest build has not fixed the issue. I have attached a project that reproduces the index out of range issue and also shows some grid redrawing problems. 1) Do not resize the window. First open the second tab that contains the grid. Thanks Chris |
|
|
Hello Chris Thanks for the repro project, I have been able to reproduce both issues. When measuring the grid, the DataGrid first gets the number of items that needs to be displayed, including any hierarchical children that have expanded parents. It then uses this stored value as an upper limit of looping through the items to display. It seems that somehow between getting this value and looping through the items, the number of items to display drops. As though collapsing one of the hierarchical items is causing multiple items to collapse. This could be a binding or reference issue which is going to take some time to look into. I'll let you know how it goes. Jason Fauchelle |
|
|
Hi Jason Is there any chance you will have resolved these issues by the end of this week? We are very close to releasing an update of our software and we would obviously like these issues resolved before then. Thanks Chris |
|
|
Hello Chris I'll look into it today or tomorrow. We should be able to get it done by the end of the week. Jason Fauchelle |
|
|
Hello Chris The source of all the problems are coming from the Binding that you've setup in the Setter of the CustomDataGridCellContainerStyle - Binding IsExpanded on the container to IsExpanded on your model objects. If I remove this binding on your repro project, then I am no longer able to reproduce any of the problems. I have spent the most part of a day looking into why this binding is causing these issues, but ultimately it's not making any sense. It looks like the binding is somehow linking the visual objects of one row to the model object of a different row. When clicking the expansion toggle on one row, both that row and another row expands which can cause the disappearance and out-of-bounds issues. But from my debugging, there is no link between the binding contexts or the model objects to explain why this is happening. I will keep looking into this, but I don't know if a solution will be available this week. Is the IsExpanded property being used a lot in your application? In the repro project, it doesn't seem to be working well at all. You may need to find a different way to keep track of the expansion state of the items. In any case, for now I recommend removing the IsExpanded binding. If this means an inability to track the expansion states, this should at least be better than a bug that causes the application to crash. Jason Fauchelle |
|
|
Hi Jason We use the IsExpanded binding throughout our application. We use this binding to expand/collapse rows based upon user interaction with other UI controls. Is there is a way we can expand/collapse a row in code then I could probably write an attached behaviour, although this would require significant changes to our codebase. Thanks Chris |
|
|
Hello Chris The DataGrid has Expand and Collapse methods that take in one of the model objects in the ItemsSource. Jason Fauchelle |
|
|
Hello Chris Unfortunately in the end I was unable to get the DataGrid to support the scenario of binding the IsExpanded property to the model items. I have made a note to include better support for this in a future version. I hope that making an attached behavior using the Expand and Collapse methods is not difficult. Jason Fauchelle |
|