WinForm的DataGridView 下拉滚动条消失
代码如下:
//这样写
Thread th = new Thread(() => {
this.CheckTable(dataFileDB,dataDB, dt);//通过多线程给dt(datatable)赋值
this.Invoke(new Action(() => {
MessageBox.Show("加载完毕");
}));
});
th.Start();
dgvShow.DataSource = dt;
虽然能够赋值能够,但是下拉框消息
Thread th = new Thread(() => {
this.CheckTable(dataFileDB,dataDB, dt);//通过多线程给dt(datatable)赋值
this.Invoke(new Action(() => {
MessageBox.Show("加载完毕");
dgvShow.DataSource = dt;
}));
});
th.Start();
或者 以下写法:
Thread th = new Thread(() => {
this.CheckTable(dataFileDB,dataDB, dt);//通过多线程给dt(datatable)赋值
this.Invoke(new Action(() => {
MessageBox.Show("加载完毕");
dgvShow.DataSource=null;
dgvShow.DataSource = dt;
}));
});
th.Start();
dgvShow.DataSource = dt;
问题原因:由于DataGridView是主线程创建的,在子线程数据绑定是要提交回主线程