PorgressBar Not Updating

3 posts, 0 answers
  1. Florian
    Florian avatar
    14 posts
    Member since:
    Dec 2014

    Posted 17 Feb 2015 Link to this post

    Hi all, 

    i want to make a ProgressDialog.

    User clicks on button "Delete", then ProgressDialog opens and Progress should be shown.

    This is my code for the dialog class:

    Public Class ProgressDialog
     
        Public Property MessstelleItems As New List(Of tblMessstelleVerzeichnisNeue)
        Public Property ZahlerItems As New List(Of tblZahler)
        Public Property MessstellenPage As MessstellenPage
        Public Property ZahlerPage As ZahlerPage
     
        Private _ctx As EnergieManagementDataContext
     
        Public Sub New(ByVal ctx As EnergieManagementDataContext)
     
            ' This call is required by the designer.
            InitializeComponent()
            _ctx = ctx
            ' Add any initialization after the InitializeComponent() call.
     
        End Sub
     
        Protected Overrides Sub OnShown(ByVal e As EventArgs)
            MyBase.OnShown(e)
            DoWork()
        End Sub
     
        Private Sub DoWork()
            RadProgressBar.Minimum = 0
     
            If MessstelleItems.Count > 0 Then
                RadProgressBar.Maximum = MessstelleItems.Count
                For Each item In MessstelleItems
     
                    Dim index = MessstelleItems.IndexOf(item) + 1
                    ProgressRadLabel.Text = "Lösche Messstelle " + index.ToString() + " von " + MessstelleItems.Count.ToString()
                    RadProgressBar.Value1 = MessstelleItems.IndexOf(item) + 1
                    Me.Refresh()
     
                    Dim tmp As New List(Of tblMessstelleVerzeichnisNeue)
                    tmp.Add(item)
                    MessstellenPage.CurrentMeasuringPoints = (From p In _ctx.tblMessstelleVerzeichnisNeues.ToList() Join r In tmp On p.MessstelleVerzeichnisID Equals r.MessstelleVerzeichnisID Select p).Distinct().ToList()
                    MessstellenPage.DeleteCurrentMeasuringPoints()
     
                Next
     
            Else
     
            End If
        End Sub
     
    End Class
    The deletion progress works fine. Only the Progressbar isnt displayed.

    ProgressDialog is started as a modal Dialog:

    Using dataContext = New EnergieManagementDataContext
        Dim dlo As New DataLoadOptions()
        dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisZeiches)
        dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisMessbereiches)
        dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisStorungsbereiches)
        dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisVersionZahlerKanals)
        dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisVersionVerantwortliches)
        dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblMessstelleVerzeichnisAreal)
        dlo.LoadWith(Of tblMessstelleVerzeichnisVersion)(Function(r) r.tblDokumentes)
        dlo.LoadWith(Of tblMessstelleVerzeichnisVersionZahlerKanal)(Function(r) r.tblZahlerKanal)
        dlo.LoadWith(Of tblZahlerKanal)(Function(r) r.tblZahlerVersion)
        dataContext.LoadOptions = dlo
     
        Dim progress As New ProgressDialog(dataContext)
     
        items = RadGridViewMessstellen.SelectedRows.Select(Function(c) CType(c.Tag, tblMessstelleVerzeichnisNeue)).ToList()
     
        progress.MessstellenPage = Me
        progress.MessstelleItems = items
        progress.ShowDialog()
     
    End Using

    No need to check DialogResult, just for blocking thread stepping out of the using block.

    Any suggestions why the ProgressBar isnt updated when function runs. 
    When work is completed the RadProgressBar shows the full Progress.

    thx
  2. Florian
    Florian avatar
    14 posts
    Member since:
    Dec 2014

    Posted 19 Feb 2015 in reply to Florian Link to this post

    Found a solution,

    After Value1 is set, call Application.DoEvents() this will update ui.

    http://www.telerik.com/forums/radprogressbar-and-waiting-status this solution helped me too. Worked also with threads.
    BackgroundWorker hasn't worked in my case, got some Strange index out of bound exception, but couldn't figure out why it was thrown. So i took first solution.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 19 Feb 2015 Link to this post

    Hello Florian,

    Thank you for writing.

    In this case your solution is correct and you should call the Application.DoEvents method.

    Here is an example with BackgroundWorker in case you need it:
    Public counter As Integer
     
    Private Sub worker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
        For index As Integer = 1 To 100
            counter += 1
            Thread.Sleep(1000)
        Next index
    End Sub
     
    Private Sub UpdateProgressBar(ByVal newValue As Integer)
        Me.radProgressBar1.Value1 = newValue
        Me.radProgressBar1.Text = "<html><span style=""font-size: 14pt""><strong>" & Me.radProgressBar1.Value1.ToString() & " %</strong></span></html>"
        Me.radProgressBar1.Invalidate()
        Application.DoEvents()
        Thread.Sleep(1000)
    End Sub
     
    Private Sub radButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim worker As New BackgroundWorker()
        AddHandler worker.DoWork, AddressOf worker_DoWork
        worker.RunWorkerAsync()
     
        Do While ((worker IsNot Nothing) AndAlso worker.IsBusy)
            If Me.radProgressBar1.Maximum >= Me.radProgressBar1.Value1 + counter Then
                UpdateProgressBar(Me.radProgressBar1.Value1 + counter)
            Else
                UpdateProgressBar(Me.radProgressBar1.Maximum)
                Exit Do
            End If
        Loop
    End Sub

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top