?
Solved

VB.NET and OpenFileDialog control.

Posted on 2010-08-26
17
Medium Priority
?
1,613 Views
Last Modified: 2013-11-27
Using VS2005 on a Windows 7 machine.
Form1 opens form2 that opens form3 that opens form4.  Form4 contains a button that invokes an OpenFileDialog control.
When invoked, the dialog box displays a "Parent" folders pane, a scroll bar, a "child" pane and another scroll bar.
If I move the mouse around and move it over a scroll bar the app will "crash" with a memory violation error that cannot be captured in a Try... Catch.
If I put a OpenFileDialog control on form1 it works fine.
Any thoughts?  More info needed?
0
Comment
Question by:classnet
[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
  • 6
  • 4
  • 3
  • +3
17 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33530749
do you use ShowDialog to open each form?can you post a screenshot of ther 4 forms with the file dialog dispalyed?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33530867
instead of adding a OpenFileDialog control to your form, declare one by code when you need one as shown in http://www.emoreau.com/Entries/Articles/2003/06/Common-Dialogs.aspx 
0
 

Author Comment

by:classnet
ID: 33531075
emoreau:  Same issue results.

Error.JPG
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33531215
Can you open form like class and object.

Example

form2 form should have class like form2
on form1 create a object of form2 and using that object open form2. same with other. I hope it will work for you.

Please let me know if you are unable to understand my answer.
0
 
LVL 16

Expert Comment

by:13598
ID: 33531692
If you comment out the line where you set the initial directory does it still error out?
 
0
 
LVL 16

Expert Comment

by:13598
ID: 33531872
Is this a duplicate question?
It seems like this issue (even same form names) was marked as resolved by you by adding an openfiledialog control on the first form?
http://www.experts-exchange.com/Programming/Languages/.NET/Q_26321832.html#a33305660 
0
 
LVL 16

Expert Comment

by:13598
ID: 33531958
I don't get that error even with 4 forms where form1 calls form2 calls form3 calls form4 and opens the openfiledialog object just fine.
However I found this issue being related to a damaged component of Microsoft .NET Framework 2.0 or 3.5 after a windows update.
Close your project, do a repair on your .net framework (whichever you are using) or a re-install and the error should go away.
0
 

Author Comment

by:classnet
ID: 33533862
13598:  Commenting out the error does not help.  I had previously posted this same question... don't recall accepting an answer... in fact I think I was just explaining that it works if put onto the first form.

I'm going to try a .net repair.
0
 

Author Comment

by:classnet
ID: 33533970
Ok... I look in add/remove programs and see no references to .NET framework except for a Compact 2.0 version.
I have no idea what is installed or how to go about repairing it.
I tried to download and install 3.0 and received a "turn wndows features on or off" message.
0
 
LVL 16

Expert Comment

by:13598
ID: 33534361
Try repairing the compact 2.0 version.
Do you also see a Microsoft .Net framework 2.0 Service Pack2?
If you don't you should install it. You need to have SP2 since it fixed a lot of issues.
Download from here after you repair 2.0 =>
http://www.microsoft.com/downloads/details.aspx?familyid=5b2c0358-915b-4eb5-9b1d-10e506da9d0f&displaylang=en
 
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33534423
classnet, your problem is not really related to installation or something. Its related to code that you are doing. You are going into wrong direction. Its possible that for a little bit of time re-installation/repair will solve your problem, but it will not be a permanent solution.
0
 

Author Comment

by:classnet
ID: 33536091
VjSoft:  What code though?  I slap an OpenFileDialog box on a form and it crashes when the mouse moves over a scroll bar?
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33538609
have you tried it?

open form like class and object.

Example

form2 form should have class like form2
on form1 create a object of form2 and using that object open form2. same with other. I hope it will work for you.

Please let me know if you are unable to understand my answer.
0
 

Accepted Solution

by:
classnet earned 0 total points
ID: 33540451
VjSoft:  Changed the forms to pull up as you described.  Here is the result:

I can now succussfully, I think, use the control one time.  But prior to the dialog box showing the first time the line below is written in the immeadiate window.
"First-chance exception at 0x75579617 in safetyLog.exe: 0x000006BA: The RPC server is unavailable."

Then if I use, or attempt to use it, a second time this gets written and everything hangs.
"First-chance exception at 0x741d4421 in safetyLog.exe: 0xC0000005: Access violation reading location 0x0f384a9f.
A first chance exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll"

As an added test, I put the control, temporarily, on each of the forms (1 - 4) and tried them all.  They all worked perfect except for form 4.  Same results.
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 35084127
On windows 7 (32 bit) had same problem when showing the openfiledialog from a modal form loaded for the second time with data from db in it. Solution was: do not allow autoupgrade of dialog.
Dim sfv As New System.Windows.Forms.SaveFileDialog
   With sfv
     .AutoUpgradeEnabled = False
     [...]

Cimperiali
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 35093588
On windows 7 (32 bit) had same problem when showing the SaveFileDialog from  a dot net windows form application (visual studio 2010, framework 4)  with data from access db (access 2010) in it. Solution appeared to be (but was not) : do not allow autoupgrade of dialog.
Dim sfv As New System.Windows.Forms.SaveFileDialog
   With sfv
     .AutoUpgradeEnabled = False
     [...]


But error came up again. Then I noticed it was apparently randomic till I realized it did not come out if I was able to show a saveFileDialog or an OpenfileDialog before loading any data from db.

Thus true workaround is: before load anything on the form you're going to show, display a dialog asking user to choose a path and file you *might* need after (arrrg!). After that, load data. Now your can let users, if needed, to choose path and file with dialog again...

ie:
  Private Sub frmReport_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     txtFilePathName.Text = "Export_" & Now.ToString("yyyy_MM_dd_HH_mm_ss", CultureInfo.GetCultureInfo("it-It")) & ".csv"
     txtFilePathName.Text = GetSaveFileName(txtFilePathName.Text, ".csv", "Choose a csv File to save exported data", "csv |*.csv|All |*.*")
     'now load data in forms, where you can also have a button to call again the GetSaveFileName
[...]

Private Function GetSaveFileName(ByVal fileName As String,
                                    ByVal defaultExtension As String,
                                   ByVal title As String,
                                   ByVal filter As String) As String
        Dim sfv As New System.Windows.Forms.SaveFileDialog
        With sfv
            .RestoreDirectory = True
            .AddExtension = True
            .DefaultExt = defaultExtension
            .FileName = fileName
            .Title = title
            .Filter = filter
            .CheckPathExists = True
            .OverwritePrompt = True
            .ShowHelp = False

            If (.ShowDialog = DialogResult.OK) Then
                fileName = .FileName
            End If
        End With
        Return fileName
    End Function

Cimperiali
0
 

Author Comment

by:classnet
ID: 35136613
The path was the issue...
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 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