threading, what different between DataGrid Binding to Binding TextBox

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?
 
E

Etienne Charland

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
 
A

Ajay Kalra

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)
 
M

mttc

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top