RadProgressBar on MDIParent not updating when called from MDIChild

2 posts, 0 answers
  1. Ray Frangie
    Ray Frangie avatar
    2 posts
    Member since:
    May 2010

    Posted 27 May 2010 Link to this post

    Hi,

    I'm trying to update/show the status of a task which loads values from a database into a ComboBox, but the StatusStrip on the MDIParent is not updating to reflect this.

    The code extract with relation to this task is as follows. I have put the database loading to a ComboBox in it's own BackgroundWorker to assist, but still no luck.

    Code as follows:

        Private Sub frmTradingApplication_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load 
            'START: Set Theme for all Telerik Controls 
            Telerik.WinControls.ThemeResolutionService.ApplicationThemeName = AppTheme 
            'END: Set Theme for all Telerik Controls 
     
            'Force Name into Name Field 
            With rtxtTradeS1_Name 
                .Text = FullName 
                .ReadOnly = True 
            End With 
     
            'Load Data into Large Cap Combo Box 
            BgWkr_LoadComboBox.RunWorkerAsync() 
     
            'Disable Large Cap Combo Box & Other Text Box 
            rcbTradeS1_LargeCapIfYes.Enabled = False 
            rtxtTradeS1_LargeCapUnlisted.Enabled = False 
     
     Private Sub rcbTradeS1_LargeCapIfYes_SelectedIndexChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles rcbTradeS1_LargeCapIfYes.SelectedIndexChanged 
            Select Case rcbTradeS1_LargeCapIfYes.SelectedItem.ToString 
                Case "Please Select Large Cap Stock..." 
                    ErrorProvider_NewTrade.SetError(rtxtTradeS1_LargeCapUnlisted, "Invalid Selection!"
                Case "Other / Not Listed - Other / Not Listed" 
                    rcbTradeS1_LargeCapIfYes.Enabled = True 
                    rtxtTradeS1_LargeCapUnlisted.NullText = "Please enter the Large Cap Stock you are trading here..." 
                Case Else 
                    'Large Cap Selection OK / Disable & Clear Unlisted Box 
                    With rtxtTradeS1_LargeCapUnlisted 
                        .Enabled = False 
                        .NullText = "Large Cap Selection OK" 
                    End With 
            End Select 
        End Sub 
     
        Private Sub rrbTradeS1_LargeCapYes_ToggleStateChanged(ByVal sender As System.ObjectByVal args As Telerik.WinControls.UI.StateChangedEventArgs) Handles rrbTradeS1_LargeCapYes.ToggleStateChanged 
            If rrbTradeS1_LargeCapYes.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On Then 
                rcbTradeS1_LargeCapIfYes.Enabled = True 
            Else 
                rcbTradeS1_LargeCapIfYes.Enabled = False 
            End If 
        End Sub 
     
        Private Sub rrbTradeS1_LargeCapNo_ToggleStateChanged(ByVal sender As System.ObjectByVal args As Telerik.WinControls.UI.StateChangedEventArgs) Handles rrbTradeS1_LargeCapNo.ToggleStateChanged 
            If rrbTradeS1_LargeCapYes.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On Then 
                rcbTradeS1_LargeCapIfYes.Enabled = True 
            Else 
                rcbTradeS1_LargeCapIfYes.Enabled = False 
            End If 
        End Sub 
     
        Private Sub BgWkr_LoadComboBox_DoWork(ByVal sender As System.ObjectByVal e As System.ComponentModel.DoWorkEventArgs) Handles BgWkr_LoadComboBox.DoWork 
            Try 
                BgWkr_LoadComboBox.WorkerReportsProgress = True 
                My.Forms.frmMain.sbarProgress.ShowProgressIndicator = True 
     
                Dim dbAdapter As New SqlDataAdapter("SELECT * FROM eTAS.dbo.viewLargeCapStockOrigins", My.Settings.eTASConnectionString) 
                Dim dbDataSet As New DataSet 
                Dim PercentValue As Integer 
                Dim RowCounter As Integer = 0 
                dbAdapter.Fill(dbDataSet) 
     
                For Each dbRow As DataRow In dbDataSet.Tables(0).Rows 
                    RowCounter += 1 
                    Dim rcbTradeS1_LargeCapIfYesItem As New Telerik.WinControls.UI.RadComboBoxItem 
                    rcbTradeS1_LargeCapIfYesItem.Text = "" 
                    rcbTradeS1_LargeCapIfYesItem.Text = dbRow.Item("CountryName").ToString & " - " & dbRow.Item("LargeCapStockName").ToString 
                    rcbTradeS1_LargeCapIfYesItem.Value = dbRow.Item("CountryName").ToString & " - " & dbRow.Item("LargeCapStockName").ToString 
                    rcbTradeS1_LargeCapIfYes.Items.Add(New Telerik.WinControls.UI.RadComboBoxItem(rcbTradeS1_LargeCapIfYesItem.Text, CObj(rcbTradeS1_LargeCapIfYesItem.Value))) 
                    PercentValue = CInt(((RowCounter / dbDataSet.Tables(0).Rows.Count) * 100)) 
                    BgWkr_LoadComboBox.ReportProgress(PercentValue, "Loading Large Cap Stocks... " & PercentValue & "% Complete..."
                Next 
     
            Catch ex As Exception 
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Load Combo Box Error..."
            End Try 
     
        End Sub 
     
        Private Sub BgWkr_LoadComboBox_ProgressChanged(ByVal sender As ObjectByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BgWkr_LoadComboBox.ProgressChanged 
     
            Try 
                My.Forms.frmMain.sbarStatus.Text = e.UserState 
                My.Forms.frmMain.sbarProgress.Value1 = e.ProgressPercentage 
                My.Forms.frmMain.sbarMain.Refresh() 
                CollectGarbage() 
            Catch ex As Exception 
                MsgBox(ex.Message & vbCrLf & vbCrLf & ex.InnerException.ToString, MsgBoxStyle.Critical, "BgWkr_LoadComboBox_ProgressChanged Error"
            End Try 
     
        End Sub 
     
        Private Sub BgWkr_LoadComboBox_RunWorkerCompleted(ByVal sender As ObjectByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BgWkr_LoadComboBox.RunWorkerCompleted 
     
            My.Forms.frmMain.sbarStatus.Text = "Large Cap Stocks Loaded OK" 
            My.Forms.frmMain.sbarProgress.Value1 = 0 
            My.Forms.frmMain.sbarMain.Refresh() 
            CollectGarbage() 
     
        End Sub 

    Your prompt reply and assistance is greatly appreciated

    Cheers,
    Ray.

  2. Ray Frangie
    Ray Frangie avatar
    2 posts
    Member since:
    May 2010

    Posted 27 May 2010 Link to this post

    Never Mind... I fixed it...

    The My.Forms.etc... doesn't work...

    To call the object on the MDIParent from the MDIChild, you need to DirectCast it as follows:

    Private Sub BgWkr_LoadComboBox_ProgressChanged(ByVal sender As ObjectByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BgWkr_LoadComboBox.ProgressChanged 
     
            Try 
                Dim MDIParent As frmMain = DirectCast(Me.MdiParent, frmMain) 
                With MDIParent 
                    .sbarStatus.Text = e.UserState 
                    .sbarProgress.Value1 = e.ProgressPercentage 
                    .sbarMain.Refresh() 
                End With 
                MDIParent = Nothing 
                CollectGarbage() 
            Catch ex As Exception 
                MsgBox(ex.Message & vbCrLf & vbCrLf & ex.InnerException.ToString, MsgBoxStyle.Critical, "BgWkr_LoadComboBox_ProgressChanged Error"
            End Try 
     
        End Sub 


    That's it... It's as simple as that :)

    Cheers,
    Ray.

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top