我要用进度条progressBar1显示datagridview读取数据的进度,谁能提供个好的代码,新手谢谢大家了!!!

解决方案 »

  1.   

    可以用模态对话框进度条的方式实现
    http://hi.baidu.com/xdragon/blog/item/b845c650b745f0591138c253.html
      

  2.   

    这是我考试系统下载试卷的进度显示,你可以参考改一下 private void toolStripButton_DownAnswer_Click(object sender, EventArgs e)//开始下载试卷
            {
                DataCollection<AnswerPaperSDO> source = this.Input;
                if (source == null||source.Count==0)
                {
                    MessageBox.Show("请先查找试卷");
                    return;
                }
                toolStripProgressBar1.Minimum = 0;
                toolStripProgressBar1.Maximum = source.Count;
                status_Progress.Text = "0/" + source.Count.ToString();
                backgroundWorker1.RunWorkerAsync(source);
            }
      private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
            {
                toolStripProgressBar1.Value = e.ProgressPercentage;
                status_Progress.Text = toolStripProgressBar1.Value.ToString() + "/" +     toolStripProgressBar1.Maximum.ToString();
            }
     private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
                if (!e.Cancelled)
                    MessageBox.Show("学生答卷下载完毕!");
                else
                    MessageBox.Show("取消下载");
            }
     private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
            {
                Serailize sera = new Serailize();            if (e.Cancel)
                {
                    MessageBox.Show("ff");
                    return;
                }
                DataCollection<AnswerPaperSDO> answerPaperCollection = e.Argument as DataCollection<AnswerPaperSDO>;
                for (int i = 0; i < answerPaperCollection.Count; i++)
                {
                    if (backgroundWorker1.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                    AnswerPaperSDO data = answerPaperCollection[i];
                    //找到目录下的试卷目录,
                    //如果找到答卷,继续
                    //没有写文件
                    //answerPaper.PaperId
                    string paperPath = getWorkFolder() + data.PaperId.ToString();
                    if (!Directory.Exists(paperPath))
                        Directory.CreateDirectory(paperPath);
                    string answerPath = paperPath + "\\" +data.StudentCode+"——"+ data.AnswerPaperId.ToString();
                    if (!Directory.Exists(answerPath))
                        Directory.CreateDirectory(answerPath);
                    string paperName = paperPath + "\\" + data.PaperId.ToString();
                    if (!File.Exists(paperName))
                    {
                        PaperFullSDO paper = getPaperService().FindFullByID(data.PaperId);
                        sera.ObjectToBin(paper, paperName, false);
                    }                string filePath = answerPath + "\\" + data.AnswerPaperId.ToString();
                    if (!File.Exists(filePath))
                    {
                        AnswerPaperFullSDO answerPaper = getProxy().FindSimpleByID(data.AnswerPaperId);
                        sera.ObjectToBin(answerPaper, filePath, false);
                    }
                    backgroundWorker1.ReportProgress(i + 1);
                }
            }
      

  3.   

    The progress you need to get is from business logic code but not DataGridView. For example, when you read data from database, you can create a model dialog window and use multi-threading technology to show the progress on the model dialog window, beause a model window can block the current thread and cause the application not responding.
      

  4.   

    比如用个Panel或Div,下载完数据后隐藏
      

  5.   

    进度条progressBar1显示datagridview读取数据的进度,我就是要这样而已,进度条跟datagridview同一个窗体,能给个例子吗/?