Solved

Can't close open file dialog before moving onto next function

Posted on 2004-08-25
4
234 Views
Last Modified: 2011-10-03
Hi everyone,
I posted this in the VB section and was advised to re-post here.

Hi all,
I have a program that reads in large files. At the moment once a user selects the file to load the open file dialog box stays on the screen and the program looks like its crashed until the file has finally been read. I have set up a label to display the loading progress on the main form, but this is never seen because the open file dialog doesn't dissapear.

I guess what i'm asking is:
Is there a way to make sure that the open file dialog has closed, and that the main form has focus before moving onto the next function?

i've tried
Dim file As String = Me.OpenFileDialog1.FileName
Me.OpenFileDialog1.Dispose()
LoadFile(file)

to no avail.
I've also tried doing an infinite loop until the filename is nothing, or until the file dialog is nothing. Neither worked.

Any suggestions gratefully received.

Cheers
DRB2k2


ok, i'll try to be a bit clearer.

I am using a standard OpenFileDialog right off the toolbar, with absolutely no modifications from me what-so-ever (save for filtering the file extension).

Whats appears to be happening is that as soon as the open button is clicked the filename is passed onto the load function BEFORE the dialog has closed.

There seems to be no way to tell if the openfiledialog class has been closed so I can't halt the load function until the dialog has dissapeared.

The files I am loading in are 3D files that specify the number of vertices they have. What I'm doing to monitor the loading is every time one is read I change the text of a label to show this.

BUT, since the openfiledialog never closes, it still has focus and the background window is never redrawn.
So what happens if after a few seconds the dialog dissapears and presents the user with a label saying "100/100 vertices read". Which is completely useless.

cheers
DRB2k2
0
Comment
Question by:drb2k2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 11892283
Here is a example of what I use with a IMAGE.
You can change it to fit your needs.  

Public Sub OpenIcon()
        Dim i As Short
        Dim myOpenFileDialog As New OpenFileDialog
        With myOpenFileDialog
            .CheckFileExists = True
            .DefaultExt = "bmp"
            .Filter = "Icon files(*.ico)|*.ico"
            .Filter += "|Bmp files (*.bmp)|*.bmp"
            .Filter += "|Jpeg files(*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg"
            .Filter += "|Gif files(*.gif)|*.gif"
            .Filter += "|Tif files(*.tif;*.tiff)|*.tif"
            .Filter += "|Png files(*.Png)|*.Png"
            .InitialDirectory = "c:\"
            .Multiselect = False
        End With
        ' Use the OpenFileDialog and put the path and name of the selected file in a var.
        If myOpenFileDialog.ShowDialog = DialogResult.OK Then                  '<------ This is what you need
            'DO SOMETHING WITH FILE
        End If
    End Sub
0
 

Author Comment

by:drb2k2
ID: 11903153
Excellent. I also needed a refresh and doevents call after updating the labels. There were two people who contributed on the same question in a different post, but didn't get the points. So I'll share the points out. If they haven't posted within a few days, I'll bung all the points your way.
Many thanks
DRB2k2
0
 
LVL 27

Accepted Solution

by:
planocz earned 125 total points
ID: 11903415
Check this link, You might like this idea of using a progress bar...

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21103610.html
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question