读书人

(WinForm,VS2005)多线程绑定绑定DataG

发布时间: 2012-03-12 12:45:33 作者: rapoo

(WinForm,VS2005)多线程绑定绑—ataGridView
请问多线程绑—ataGridView应该怎么操作
以前从来没有了解过多线程,下面是我的代码,运行时不稳定,窗体第一遍打开时数据绑定很正常,但当第二次打开窗体时会报错

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)看看呢

读书人网 >C#

热点推荐