Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET and OpenFileDialog control.

Posted on 2010-08-26
17
Medium Priority
?
1,645 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:Meir Rivkin
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

597 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