(WinForm,VS2005)多线程绑定绑定DataGridView
请问多线程绑定DataGridView应该怎么操作
以前从来没有了解过多线程,下面是我的代码,运行时不稳定,窗体第一遍打开时数据绑定很正常,但当第二次打开窗体时会报错
public partial class fm_cust_custinfo : Form
{
DataSet ds_custlist = new DataSet(); //客户列表
Thread thread;
delegate void bindgridview();
private void fm_cust_custinfo_Load(object sender, EventArgs e)
{
this.dv_list.AutoGenerateColumns = false;
this.tabControl1.SelectedIndex = 1;
CheckIsIn();
}
private void BindList()
{
string strSQL = "select * from cust_custinfo order by filldates desc ";
sqlconn.Open();
SqlCommand cmd = new SqlCommand(strSQL, sqlconn);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds_custlist);
this.dv_list.DataSource = ds_custlist.Tables[0];
}
private void BindThread()
{
ThreadStart bind = new ThreadStart(BindList);
thread = new Thread(bind);
thread.Start();
}
private void CheckIsIn()
{
if (this.dv_list.InvokeRequired)
{
bindgridview d = new bindgridview(BindThread);
this.dv_list.Invoke(d);
}
else
{
BindThread();
}
}
}
希望各位不吝赐教,小弟先谢过了
------解决方案--------------------看起来应该是对了。
最好贴错误的信息出来。
------解决方案--------------------根据错误提示看代码
------解决方案--------------------用this.dv_list.BeginInvoke(d)看看呢