This is a migrated thread and some comments may be shown as answers.

ProgressBar does not update untill after work is done!

3 Answers 2959 Views
ProgressBar
This is a migrated thread and some comments may be shown as answers.
John Hamman
Top achievements
Rank 1
John Hamman asked on 08 Apr 2008, 07:14 PM
Hi, I have an import feature that I want to display progress while its running.
the import feature is located  in a MdiChild
the progress bar is located  in a radStatusStrip on the Parent form

here is the code I have and yet the Progress bar doesn't move untill after the loop is done.

int j = Textbox_InputText.Lines.Length;
(ss.Items[1] as RadProgressBarElement).Maximum = j;
int i;
            for (i = 0; i < j; i++)
            {
                ....Do import stuff


                //I tried .Value++ also and same results
                //(ss.Items[1] as RadProgressBarElement).Value1++;
                (ss.Items[1] as RadProgressBarElement).PerformStepValue1();
            
               

            }

PLEASE Help, I am extremely frustrated with this.

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 11 Apr 2008, 11:09 AM
Hi John Hamman,

Thank you for writing.

After you call the PerformStepValue1(), you should call the Refresh() method of the RadStatusStrip. Your code should look like this:

for (i = 0; i < j; i++)  
{  
    ....Do import stuff  
 
    (ss.Items[1] as RadProgressBarElement).PerformStepValue1();   
    ss.Refresh();  

I hope this helps. Please contact me if you have additional questions.

Greetings,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Gal
Top achievements
Rank 2
answered on 17 Feb 2013, 08:19 AM
Hi I have been using this code to display message and progress while a long task is running BUT it only refreshes at the end making it pointless!  

private void statOnline_SetUp()
{
    RadLabelElement labelElement = new RadLabelElement();
    labelElement.Text = "Running...";
    CommandBarSeparator separator = new CommandBarSeparator();
    RadProgressBarElement progressBarElement = new RadProgressBarElement();
    progressBarElement.Text = "0";
    radStatusStrip1.Items.AddRange(new RadItem[] { labelElement, separator, progressBarElement });
    radStatusStrip1.Update();
    radStatusStrip1.Refresh();
    this.Refresh();
 
}

private
void SetMessage(string myMessage, int FilePos, int FileTotal)
{
    if (radStatusStrip1 != null)
    {
        RadLabelElement labelElement = radStatusStrip1.Items[0] as RadLabelElement;
        RadProgressBarElement progressBarElement = radStatusStrip1.Items[2] as RadProgressBarElement;
        labelElement.Text = myMessage;
        progressBarElement.Minimum = 0;
        progressBarElement.Maximum = FileTotal;
        progressBarElement.Value1 = FilePos;
        progressBarElement.Step = 1;
        progressBarElement.PerformStepValue1();
        progressBarElement.Text = FilePos.ToString();
        progressBarElement.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        radStatusStrip1.Update();
        radStatusStrip1.Refresh();
 
    }
}
 

0
Nikolay
Telerik team
answered on 18 Feb 2013, 09:57 AM
Hi Gal,

The behavior that you are observing is due to our layouts. They are asynchronous and in the case that you have they may not be updated at the exact time you need them. Therefore, you need to update them manually. Please consider the code snippet below which correctly updates the text of the label and the fill of the progress bar:

private void statOnline_SetUp()
{
    RadLabelElement labelElement = new RadLabelElement();
    labelElement.Text = "Running...";
    labelElement.AutoSize = true;
    CommandBarSeparator separator = new CommandBarSeparator();
    RadProgressBarElement progressBarElement = new RadProgressBarElement();
    progressBarElement.Text = "0";
    radStatusStrip1.Items.AddRange(new RadItem[] { labelElement, separator, progressBarElement });
}
 
private void SetMessage(string myMessage, int FilePos, int FileTotal)
{
    if (radStatusStrip1 != null)
    {
        RadLabelElement labelElement = radStatusStrip1.Items[0] as RadLabelElement;
        RadProgressBarElement progressBarElement = radStatusStrip1.Items[2] as RadProgressBarElement;
        labelElement.Text = myMessage;
        progressBarElement.Minimum = 0;
        progressBarElement.Maximum = FileTotal;
        progressBarElement.Value1 = FilePos;
        progressBarElement.Step = 1;
        progressBarElement.PerformStepValue1();
        progressBarElement.Text = FilePos.ToString();
        progressBarElement.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        radStatusStrip1.RootElement.UpdateLayout();
        radStatusStrip1.Refresh();
    }
}

The two important lines are at the bottom of the SetMessage method.

I hope this helps.
 
Regards,
Nikolay
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
ProgressBar
Asked by
John Hamman
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Gal
Top achievements
Rank 2
Share this question
or