Reputation: 77
I am using VS express 2010 and .Net 4.0.
I bind a DataGridView to a BindingList which implement INotifyPropertyChanged.
The value changed is reflected on the grid normally but failed when using Threading.Timers to do the update job.
As shown below , the value is updated but not shown unless the cells lost focus like "minimizing and maximizing" or "the grid is covered by other window" or "selecting the cells".
http://i.minus.com/jViIpKKeNNRrB.PNG
I am a newbie. I had searched and I believe the threading.timer is bad in updating UI. But in my case, I am just updating the value.
I am tired of playing with the weak threading.timer. Any other recommendations for light-weighted timer would be appreciated! Thank you.
Upvotes: 2
Views: 424
Reputation: 117019
The Threading.Timer
isn't "bad" at updating the UI, it just fires its event on a different thread to the UI thread and since UI must be updated on the UI thread you're having your difficulties.
You need to Invoke
the update back on the UI thread.
The easiest way to do this is:
myControl.Invoke((Action)(() =>
{
myControl.Text = "Hello";
}));
Obviously replace your code into my example.
Let me know if this works.
Upvotes: 2