ProgressBar does not update untill after work is done!

4 posts, 0 answers
  1. John Hamman
    John Hamman avatar
    10 posts
    Member since:
    Feb 2006

    Posted 08 Apr 2008 Link to this post

    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.
  2. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 11 Apr 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Gal
    Gal avatar
    48 posts
    Member since:
    Apr 2009

    Posted 17 Feb 2013 Link to this post

    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();
     
        }
    }
     

  5. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 18 Feb 2013 Link to this post

    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.
Back to Top