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.
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 = ""
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
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