我想用后台工作者填充网格,但我不知道必须添加DataGrid.DataSource=DataTable;
的位置是否有任何简单的示例解释如何使用后台工作程序来填充DataGrid
?
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
setgride();
}
private void setgride()
{
string constring = "constring";
SqlCommand com = new SqlCommand();
SqlConnection con = new SqlConnection(constring);
com.Connection = con;
com.CommandText = " select * from Request";
SqlDataAdapter adapt = new SqlDataAdapter(com);
DataTable dt2 = new DataTable();
adapt.Fill(dt2);
propdt2 = dt2;
}
private void button1_Click(object sender, EventArgs e)
{
this.backgroundWorker1.RunWorkerAsync();
}
答案 0 :(得分:3)
,处理此事件并在此处分配源属性。