Solved

VB.NET and OpenFileDialog control.

Posted on 2010-08-26
17
1,485 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
  • 6
  • 4
  • 3
  • +3
17 Comments
 
LVL 42

Expert Comment

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

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
emoreau:  Same issue results.

Error.JPG
0
 
LVL 8

Expert Comment

by:Mohit Vijay
Comment Utility
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
Comment Utility
If you comment out the line where you set the initial directory does it still error out?
 
0
 
LVL 16

Expert Comment

by:13598
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:classnet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The path was the issue...
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now