1

我想用后台工作人员填充网格,但我不知道必须在哪里添加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();
}
4

1 回答 1

3

在 BackgroundWorker.RunWorkerCompleted Event 中,处理此事件并在此处分配源属性。

于 2013-03-11T05:59:49.677 回答