0

我正在填充一个datagridview

MyDataGridView.DataSource = MyList;

其中 MyList 是一个 List < MyClass > 。现在我希望在填充 datagridview 时填充进度条。我可以做 MyProgessBar.Maximum = MyList.Count,但是如何在每次绘制一行时设置 MyProgressBar 值?

4

1 回答 1

0

这是背景工作者的解决方案......我没有找到其他任何东西,但这适用于我必须做的事情

    private void PopulateDataGridView()
    {
        MyProgressBar.Value = 0;
        MyProgressBar.Maximum = MyList.Count;
        MyBackGroundWorker.RunWorkerAsync();
        MyDataGridView.DataSource = MyList;
    }

进而

    private void MyBackGroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        while (true)
        {
            MyBackGroundWorker.ReportProgress(MyDataGridView.Rows.Count);
            if (MyDataGridView.Rows.Count == MyProgressBar.Maximum)
            {
                break;
            }
            System.Threading.Thread.Sleep(100);
        }

    }

    private void MyBackGroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        MyProgressBar.Value = MyDataGridView.Rows.Count;
    }
于 2013-02-03T14:07:19.757 回答