Progress bar problem while processing records

Posted by Dipu710646 under C# on 2/16/2011 | Points: 10 | Views : 6537 | Status : [Member] | Replies : 8
Hi All,

I have 5000 records in my datatable. I will do some processing on each row.I want to show the progess in progress bar.
How will I go for it?

I have writen some code. But it is not doing exactly I wanted..Please check it once...

progressBar1.Minimum = 0;
progressBar1.Maximum = ds.Tables[0].Rows.Count;
progressBar1.Step = 1;
for (int count = 0; count < ds.Tables[0].Rows.Count; count++)
{
progressBar1.PerformStep();
progressBar1.Refresh();
DataRow dr = Dt.NewRow();
for (int ColCount = 0; ColCount < 60; ColCount++)
{
if (ds.Tables[0].Rows[count][ColCount].ToString().Length > 2)
{
///some task...
}
else
{
dr[ColCount] = string.Empty;
}

}
Dt.Rows.Add(dr);


}

Any reply is appreciated.

Thanks,
Dipankar




Responses

Posted by: T.saravanan on: 2/17/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

To using Timer control to set the progress bar value...
For your reference..
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/fb32a195-8a2c-4c4e-8910-b96727ca9f5f/
http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithProgressBarinCSharp11302005045625AM/WorkingwithProgressBarinCSharp.aspx

Cheers :)

Thanks,
T.Saravanan

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dipu710646 on: 2/17/2011 [Member] Starter | Points: 25

Up
0
Down
I think you dont understand my problem clearly..

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 2/17/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

I understood, those link gives some idea to you.
Any way try this code....

Add one Timer Control in your form..
Private void btn_Click(object sender, EventArgs e)

{
progressBar1.Minimum = 0;
progressBar1.Maximum = ds.Tables[0].Rows.Count;
progressBar1.Step = 1;
progressBar1.Visible = true;
for (int count = 0; count < ds.Tables[0].Rows.Count; count++)
{
timer1.Start();
// Your Code
}
}

private void timer1_Tick(object sender, EventArgs e)
{
if(progressBar1.Value < ds.Tables[0].Rows.Count)
{
progressBar1.Value += progressBar1.Step;
}
else
{
timer1.Stop();
progressBar1.Visible = false;
// Your Message [Progress Completed]
}
}


Cheers :)


Thanks,
T.Saravanan

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 2/17/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
instead of using the timer control place the code
progressBar1.Value += progressBar1.Step;
inside the loop where you have timer1.Start();

Because timer control runs based on time set to it .. which may be bit different then the actual time taken to load the data.

Thanks and Regards
Madhu

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dipu710646 on: 2/17/2011 [Member] Starter | Points: 25

Up
0
Down

Thanks guys..

I am some how managing to do that but problem is progressbar step is 1 ,progress bar width is 450 and loop count is 5000.

so very quickly it is completing the width..

How to manage so that it reaches the end at completion of all the records .

Thanks,
Dipankar


Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 2/17/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Check this link...

http://www.codeproject.com/KB/user-controls/progressbar.aspx

Thanks
Karthik
www.f5Debug.net

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 2/17/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
THe progress bar width should not be the problem. As the width has nothing to do with that as long as you have set the maximum value correctly.

Thanks and Regards
Madhu

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tripati.patro on: 2/18/2011 [Member] Starter | Points: 25

Up
0
Down
"Value" property is the key for ProgressBar control. Each time it needs to incremented during the operation/code.
Try this, hope this will solve your probelm.

private void btnProgress_Click(object sender, EventArgs e)

{
try
{
// Make progress bar visible before operation starts.
progBarCounter.Visible = true;
int rowCount = 1000;
progBarCounter.Minimum = 0;
progBarCounter.Maximum = rowCount;
for (int index = 1; index <= rowCount; index++)
{
// TODO: Your Operation/Code

progBarCounter.Value = index;

// TODO: Need to remove. At this moment needed as to make the control visible.
Thread.Sleep(10);
}
}
finally
{
progBarCounter.Visible = false;
}
}


B.Tripati Patro
Oracle Certified Associate

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response