Results 1 to 4 of 4

Thread: Using controls on Child from MdiParent

  1. #1
    Reggie213 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    May 2012
    Posts
    12
    Reputation
    16

    Using controls on Child from MdiParent

    Hi,

    I have an MDI windows form setup. On load it sets the child form(frmMainData) and opens it.

    I have a progress bar on my child form that I wish to show(set to visible = false in design)

    I have menu strip on my parent form.

    For simplicity I have just set the command against one of the menustrip options to do the following

    Code:
    frmMainData.ProgressBar1.Show()
    It does not work, there is no error the progressbar simply does not display.

    That is my problem in a nutshell.

    To add to this a little I actually have a sub in my child form that runs some code that I wish to execute from the menustrip and the code works fine, inside the code is some code to show the progress bar and it doesnt activate the progress bar, hence why I simplified the example above.

    Thanks

    Antony

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    Are you referring to default form instance, that 'frmMainData' is the class name, and is that also the mdi child form instance?

  3. #3
    Reggie213 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    May 2012
    Posts
    12
    Reputation
    16
    Yes the class name is frmMainData and I initiate the child form as frmMainData.

    I can call a function on the child form from the parent menustrip fine and it will run the code in it.. apart from the references to the progress bar parts.. which is what prompted me to simple making the click event of the menu strip option to set the visible parameter to true of the progress bar to ensure nothing else was secretly causing it not to work!

    Public Sub DatatableToExcel2()
    Dim _excel As Object
    Dim wBook As Object
    Dim wSheet As Object
    Dim res As DialogResult
    Dim filename As String
    filename = ""

    [B]Me.ProgressBar1.Show()
    Me.ProgressBar1.Maximum = _tmpDatatable.Rows.Count
    Me.ProgressBar1.Step = 1[/B]

    SaveFileDialog1.Filter = "(*.xls)|*.xls"
    SaveFileDialog1.Title = "Save Stock Proection Report Excel"
    res = SaveFileDialog1.ShowDialog()

    If res = DialogResult.OK Then
    If SaveFileDialog1.FileName <> "" Then
    filename = SaveFileDialog1.FileName
    'MsgBox(filename)
    End If

    _excel = CreateObject("Excel.Application")

    wBook = _excel.Workbooks.Add()
    wSheet = wBook.ActiveSheet()

    Dim dc As System.Data.DataColumn
    Dim dr As System.Data.DataRow
    Dim colIndex As Integer = 0
    Dim rowIndex As Integer = 0
    If _tmpDatatable IsNot Nothing Or _tmpDatatable.Rows.Count <> 0 Then


    For Each dc In _tmpDatatable.Columns
    colIndex = colIndex + 1
    _excel.Cells(1, colIndex) = dc.ColumnName
    Next

    For Each dr In _tmpDatatable.Rows
    rowIndex = rowIndex + 1
    colIndex = 0
    For Each dc In _tmpDatatable.Columns
    colIndex = colIndex + 1
    If dc.ColumnName <> "Check" Then
    If dc.ColumnName = "Item" Then
    _excel.Cells(rowIndex + 1, colIndex) = "'" + dr(dc.ColumnName)
    Else
    _excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
    End If
    End If

    Next
    [B]Me.ProgressBar1.PerformStep()[/B]
    Next

    wSheet.Columns.AutoFit()

    Dim strFileName As String = filename
    If System.IO.File.Exists(strFileName) Then
    System.IO.File.Delete(strFileName)
    End If

    wBook.SaveAs(strFileName)
    wBook.Close()
    _excel.Quit()
    [B]Me.ProgressBar1.Value = 0
    Me.ProgressBar1.Hide()[/B]
    Else
    MsgBox("nothing in datatable")
    End If
    End If
    End Sub
    Last edited by JohnH; 06-12-2012 at 5:54 PM. Reason: code box

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    While your code is running in UI thread nothing else can happen in that thread. A cheap option, if your operation just takes a very few seconds to complete, is to call DoEvents to let all windows messages/events to be processed. The better option in most cases is to do any time consuming processing in a secondary thread, and invoke updates back to UI thread when necessary. The BackgroundWorker component is a simple way to add multithreading in a forms application, and it includes features such as progress/completion event notification back to UI thread.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking