How DataGridView refresh and update the data source class property run time

I

Ivan

I have a class Foo which have two property. I have a thread that do
some process and update class Foo int B. I have a datagridview on main
form. this datagridview data source to this class Foo and column A
binds to string A and column B binds to int B. When i start two
threads, the datagridview able to show two rows and updated int B at
run time. How?

public class Foo
{
public Foo()
{
}

private string a;
public string A
{
set { a = value; }
get { return a; }
}

private int b;
public int B
{
set { b = value; }
get { return b; }
}
}

I try this code, but does not work.

dataGridViewBindingSource.CurrentItemChanged += new
EventHandler(dataGridViewBindingSource_CurrentItemChanged);

void dataGridViewBindingSource_CurrentItemChanged(object sender,
EventArgs e)
{
dataGridView.Refresh();
}

Anyone helps. Thanks in advance.
 
C

chanmm

For me, normally I bind to arraylist or other collection class then bind
direct to the class. Have a try.

chanmm
 
I

Ivan

Hi Chanmm,

Yes, the Foo class would be BindingList<Foo> collections and from the
book Windows Forms 2.0 Programming chapter 16
(http://www.amazon.com/gp/product/03...0921/ref=pd_bbs_1/002-9571900-8544016?ie=UTF8)
the Foo should have INotifyPropertyChanged interface so that the data
grid view will update the object class Foo property change.

Now I have another question which across my mind, does DataGridView
suitable to display dynamic multi threading data? just mainly for
viewing static data or non frequent data only? May be the multi
threading method i used does not suitable. I am using background worker
thread. Any comment?

Ivan.
 

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