This is a migrated thread and some comments may be shown as answers.

“Bounds cannot be changed while locked” on GridView update

2 Answers 191 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 30 Jul 2013, 09:46 PM

I have a List called “myResults”. When the list contains at least one item, I’m trying to populate a GridView w/ info for the list; the GridView is called “gvMyResults”. However, sometimes, during this update of the DataSource, I get an exception saying, “Bounds cannot be changed while locked”, and a red X is displayed across my GridView. I added this Dispatcher wrapper around my update, but I’m still seeing the same error. It’s difficult to troubleshoot, because it does not happen every time. Does anyone know how to stop this “bounds cannot be changed while locked” error?

I have tried to fix this two ways, but both still give the error. 

First attempt:

Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate()
{
    this.gvMyResults.DataSource = myResults;
});

Second attempt:

_Context.Send(x =>
{
    this.gvMyResults.DataSource = myResults;
}, null);

2 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 02 Aug 2013, 09:18 AM
Hello Tim,

Thank you for writing.

This error indicates that the grid is not in valid state. I noticed in the code snippet that you update the datasource asynchronously and I would like to clarify that all UI controls are not thread safe controls in the whole Windows Forms UI platform. Here is an article on MSDN describing how to make thread-safe Winforms UI application. This means that RadGridView is not thread safe as well and cannot be used outside the main UI thread. You should use an Invoke to update the controls in cross threading scenario. For example:

if (gvMyResults.InvokeRequired)
{
    gvMyResults.Invoke(new MethodInvoker(() => { this.gvMyResults.DataSource = myResults; }));
}
else
   this.gvMyResults.DataSource = myResults;
}

I hope this helps.

Regards,
Author nickname
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS. 
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>

Regards,
Peter
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Tim
Top achievements
Rank 1
answered on 08 Aug 2013, 01:20 PM
Thanks Peter!
Tags
GridView
Asked by
Tim
Top achievements
Rank 1
Answers by
Peter
Telerik team
Tim
Top achievements
Rank 1
Share this question
or