Current filter:
                                You should refresh the page.
                                  • Description:
                                    I have a data table connected to a GridControl that I'm modifying within different threads, and the XtraGrid component seems to be catching the updates automatically and trying to refresh based on the data changes. However, sometimes the application crashes with an ArgumentOutOfRangeException. How to avoid this problem?

                                    This issue is not connected with the Data Grid directly. Unfortunately, you can't change the grid's data source in a background thread since it will cause a lot of problems with synchronization. The Data Grid may perform some operations with the underlying data source at the same time as your background thread changes it. In this case the grid may receive a Change notification later and will try to update rows from the data source which will cause the mentioned problem. This problem may occur in a lot of cases. For example, when a user edits data, groups it or the Data Grid tries to recalculate the summaries. The only solution to this problem is to change the Grid's DataSource reference within a background thread (NOTE: You will need to implement it using the Invoke method). Said differently, within a background thread you should work with a local copy of the DataSource and pass its clone to the Grid's DataSource when necessary. In the attached example you will find a sample project which demonstrates this approach.
                                    See Also:
                                    Is the XtraGrid thread safe?
                                    Big red X: A control becomes crossed with red lines after an exception

                                Show all comments
                                • wesa 09.09.2012

                                  Hello, i am experiancing this problem, i've 3 grid controls with their source datatables being updated almost multiple times per second and sometimes i get this exception, i am using a back ground thread to update the datatables, could you please explain more about changing the Grid's DataSource reference within a background thread with a sample?

                                • Oleg (DevExpress Support) 09.10.2012

                                  Thank you for your question. To avoid any misunderstanding in this discussion, I have created a separate ticket on your behalf.
                                  Please refer to the following thread for further correspondence on this item: Q287564

                                • Yonatan Sion 10.30.2015

                                  Is there a way in code to catch this error when and if it happens? do you have any example anywhere? thanks (i just dont know where to put the try..catch for this specific error)

                                • Gosha (DevExpress Support) 11.02.2015

                                  Hi Yonatan,

                                  As Stan stated in his answer, this issue relates to accessing the same data of an object from several threads simultaneously rather than to our Grid. I don't think that this issue can be resolved by wrapping some code in the try/catch block, since it may occur at any moment when several threads access the same data. It's necessary to research your code for possible race conditions and deadlocks. See the How to: Make Thread-Safe Calls to Windows Forms Controls MSDN article for possible solutions to this issue.

                                • Yonatan Sion 12.02.2015

                                  I am trying to trace when I get this error, as it keeps coming back but never consistently (it could vanish for few months, then appear again)
                                  Basically, we set the GridControl1.DataSource property to a DataTable, and that's done from the main thread.  but from other threads we change the data inside that DataTable: we do .Fill() to fill it up and the data appears on the GUI (there's never a problem there) and then, later, we change various rows within the DataTable (and this is where we tend to get the error)
                                  We need to set the data from the thread so 1. the GUI will stay responsive and 2. its nice to show the user how the data appears, just like when you run a SELECT in SSMS (you see the records add up and the GUI is totally responsive)
                                  so, what can we do about it? is there any way that xtragrid can safely handle it, and the error will never come back? can we set the data into the DataTable from various threads using synchronization or something...? again, its the inconstant nature of this error that makes it confusing and hard for the developer to handle

                                • Elena (DevExpress Support) 12.03.2015


                                  Refer to the E813 example, which illustrates how to update the Grid's underlying data source from a background thread.
                                  The main idea is to create a copy of DataSource and perform all changes on this copy. And, finally, implement the Invoke method of GridControl, which will set the GridControl.DataSource property for the copy.
                                  Let me know if you need further assistance.

                                • Richard Griffiths 3 10.27.2016

                                  Is this likely to be improved in the future? The E813 example is unworkable in our scenario - I tried it but we're using table adapters and a lot less code behind than shown here. For now I've written off using async data loading and GridView as it has seemed quite intractable.

                                • Nadezhda (DevExpress Support) 10.27.2016

                                  Hello Richard,
                                  I've created a separate ticket on your behalf (GridControl - How to load data source asynchronously ). It has been placed in our processing queue and will be answered shortly.

                                0 Solutions

                                Creation Date Importance Sort by