简体   繁体   中英

C# - Updating Progress Bar

I have an application that imports excel records into a user interface to read the data. This import take a fair amount of time so I am trying to implement a progress bar for the user to see the progress.

First I did it in an external form, and everything worked fine. Now i changed it to a progress bar on the loading form and suddenly it doesn't work. All that I have done is chagne the form reference from my Class source sheet. Here is the code that does the progress bar.

The only change I made to that code is change to "OpenForm" as that is wher ethe new progress bar is. I know this code will set the progress bar to 20 and not move after that. This was working on the form which had just the progress bar, however on this one it doesnt work. Am I missing something?

        OpenForm.progressBar1.Minimum = 0;
        OpenForm.progressBar1.Maximum = 100;
        OpenForm.progressBar1.Step = 1 / 50;

        for (int row = 8; row <= 50; row++)
        { 
            IssueRef.Add(ExcelWksht1.Cells[row, 1].Value.ToString());
            Date.Add(ExcelWksht1.Cells[row, 4].Value.ToString());
            Status.Add(ExcelWksht1.Cells[row, 2].Value.ToString());
            Severity.Add(ExcelWksht1.Cells[row, 9].Value.ToString());
            Text.Add(ExcelWksht1.Cells[row, 3].Value.ToString());

            decimal ProgressVal = ( 10m /50m) * 100m;
            int Val = Convert.ToInt32(ProgressVal);

            OpenForm.progressBar1.Value = Val;
            OpenForm.progressBar1.Refresh();

        }
    for (int row = 8; row <= 50; row++)
        { 
            IssueRef.Add(ExcelWksht1.Cells[row, 1].Value.ToString());
            Date.Add(ExcelWksht1.Cells[row, 4].Value.ToString());
            Status.Add(ExcelWksht1.Cells[row, 2].Value.ToString());
            Severity.Add(ExcelWksht1.Cells[row, 9].Value.ToString());
            Text.Add(ExcelWksht1.Cells[row, 3].Value.ToString());

            decimal ProgressVal = ( 10m /50m) * 100m;
            int Val = Convert.ToInt32(ProgressVal);

            OpenForm.progressBar1.Value = Val;
            //OpenForm.progressBar1.Refresh(); remove this
//add 
Application.DoEvents();

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM