Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

   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.

  • Administrators
Posted

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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • 4 weeks later...
Posted

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

 

-----------------------------------------------------------------------------------

sOMEONE'S gONNA dO iT, wHY nOT yOU ?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...