JDYoder Posted July 18, 2005 Posted July 18, 2005 On the OpenFileDialog control, when its FileOk event is fired, I call a subroutine to do some processing on the file selected, but the dialog remains open. I can use Messageboxes and everything (which popup over top of the dialogbox) but only when my subroutine is completed and the execution returns to the FileOk event does the dialogbox close. Why won't it close on its own and/or what can I do to close it? Quote
Administrators PlausiblyDamp Posted July 18, 2005 Administrators Posted July 18, 2005 Any chance you could post the relevant code? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JDYoder Posted July 18, 2005 Author Posted July 18, 2005 Private Sub ImportGetFile() dlgOpen.ShowDialog() End Sub Private Sub dlgOpen_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles dlgOpen.FileOk Import(dlgOpen.FileName) MessageBox.Show("Bye") End Sub Private Sub Import(ByVal FileName As String) Try Me.Activate() Application.DoEvents() Me.Cursor = System.Windows.Forms.Cursors.WaitCursor dlgOpen = Nothing Dim results As Interfaces.UpdateResults = Me.BusLayer.ModuleSpecificOptions("AssetsScannedTruncate", Nothing) If results.errorNumber = 0 Then FormLoadedDataView() Dim ds As DataSet = dcMainDataControl.SearchDataView.Table.DataSet Dim ScannerFile As New System.IO.StreamReader(FileName) Dim SiteID, BuildingID, RoomID, AssetID As String SiteID = ScannerFile.ReadLine Do While Not SiteID Is Nothing BuildingID = ScannerFile.ReadLine RoomID = ScannerFile.ReadLine AssetID = ScannerFile.ReadLine Dim dr As DataRow = ds.Tables(0).NewRow dr.Item("AssetID") = AssetID dr.Item("SiteID") = SiteID dr.Item("BuildingID") = BuildingID dr.Item("RoomID") = RoomID dr.Item("Scanned") = True dr.Item("Processed") = False ds.Tables(0).Rows.Add(dr) SiteID = ScannerFile.ReadLine Loop ScannerFile.Close() If dcMainDataControl.DataSaveAll() = DialogResult.Yes Then results = Me.BusLayer.ModuleSpecificOptions("AssetsScannedVariance", Nothing) If results.errorNumber = 0 Then StatusMessage("Import completed") End If End If End If If results.errorNumber <> 0 Then StatusMessage("Database error", True, results.resultMessage) Catch exIO As System.IO.IOException StatusMessage("Error importing data.", True, exIO.Message) Catch ex As SystemException LogError(ex) Finally FormLoadedDataView() Me.Cursor = System.Windows.Forms.Cursors.Default End Try End Sub FYI, the "Bye" Messagebox is just for debugging. The "Import" function takes only a few seconds, and when it's done the "Bye" message pops up (with the dialogbox still visible behind it.) After clicking "OK" to the messagebox, the dialogbox closes. Quote
Administrators PlausiblyDamp Posted July 18, 2005 Administrators Posted July 18, 2005 In your code you have Private Sub dlgOpen_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles dlgOpen.FileOk Import(dlgOpen.FileName) MessageBox.Show("Bye") End Sub This will run during the Dialog's OK (Open) buttons click event. The dialog is only dismissed when this event has finished. You should really check to see if they clicked ok in your ImportGetFile routine and do the import if they did. i.e. Private Sub ImportGetFile() If dlgOpen.ShowDialog() = DialogResult.OK Then Import(dlgOpen.FileName) End If End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JDYoder Posted July 18, 2005 Author Posted July 18, 2005 That did the trick. Thanks -- I'd have never figured that one out. Quote
FYRe Posted August 11, 2005 Posted August 11, 2005 Here's a quick example of an OpenFileDialog: ----------------------------------------------------------------------------------- Private Sub btn_load_Click(....) Handles btn_load.Click If OpenFileDialog1.ShowDialog = DialogResult.OK Then ' when user clicks 'OK" in OpenFileDialog, the code below will be executed. ' put whatever code in here. End If End Sub ----------------------------------------------------------------------------------- Quote sOMEONE'S gONNA dO iT, wHY nOT yOU ?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.