Search This Blog

Sunday, July 17, 2011

Using progress bar in VB.NET

A simple example of how to user a progress bar.  Here we will do a
simple query, and advance through the records while showing a
progress bar.  In order to try this, simple create a new Windows
Application, and drap a progress bar control onto your form.Next,
you can add the code from below, and you should be all set.
The progress bar will automatically increase steps based on the
number of records we have in the database.This gives an idea to
the user of how long they will be waiting.


Progress Bar Code :-


DataSet DS = new DataSet();DS = GetDataSet("select * from Employees");
//Verify we have recordsif (DS != null && DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0)
{
      
//Set Progress Bar
      
ProgressBarMigration.Visible = true//Make it visible
      ProgressBarMigration.Minimum = 0;  //Set Min Steps
      ProgressBarMigration.Maximum = DS.Tables[0].Rows.Count;  //Set Number of Max Steps
      ProgressBarMigration.Value = 0;  //Initiliaze to beginning

      //parse through each record
      
foreach (DataRow dr in DS.Tables[0].Rows)
      {
            ProgressBarMigration.Value += 1;
            System.Threading.
Thread.Sleep(50);  //Sleep to slow down to see steps

            //Ideally here you would do your transactions
      }
      ProgressBarMigration.Visible =
false;
      
MessageBox.Show("Migration Complete.");
}

1 comment: