threading, what different between DataGrid Binding to Binding TextBox

  • Thread starter Thread starter mttc
  • Start date Start date
M

mttc

I read this article:
HOW TO: Populate Datagrid on Background Thread with Data Binding by Using
Visual
http://support.microsoft.com/kb/318604/

I try it, I call from new thread to binding DS to control . And I find out:

This code throws exception:

DataGrid1.DataSource = Ds
DataGrid1.DataMember = "Table1"

And this code not make any problem:
Textbox1.DataBindings.Add("text", Ds, "Table1.Colum1")


I wonder what different between?
 
Do you mean it throws an exception when you run that code from the worker
thread? If so, keep in mind that only the main thread should work with the
UI. If you try from another thread, it might work, or it might not work;
results are unpredictable. So even if it sometimes work, don't do it :) To
run a method under the main thread, use the form's Invoke method.

I hope this helps.

Etienne
 
You should not call DataGrid methods/properties from the background thread.
Use BeginInvoke/Invoke on the grid from worker thread. I have used this
article and it *mostly* works fine as is.

_____________
Ajay Kalra (MVP - VC++)
(e-mail address removed)
 
I still not understand, at microsoft Example itself,

I see this line:


Public Sub QueryDataBase()

...

-->> Label1.Text = "DataSet Filled"


This is not call to UI from another thread.
 
Back
Top