Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1678
  • Last Modified:

VB.NET and OpenFileDialog control.

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
classnet
Asked:
classnet
  • 6
  • 4
  • 3
  • +3
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
do you use ShowDialog to open each form?can you post a screenshot of ther 4 forms with the file dialog dispalyed?
0
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
classnetAuthor Commented:
emoreau:  Same issue results.

Error.JPG
0
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.

 
Mohit VijayCommented:
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
 
13598Commented:
If you comment out the line where you set the initial directory does it still error out?
 
0
 
13598Commented:
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
 
13598Commented:
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
 
classnetAuthor Commented:
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
 
classnetAuthor Commented:
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
 
13598Commented:
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
 
Mohit VijayCommented:
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
 
classnetAuthor Commented:
VjSoft:  What code though?  I slap an OpenFileDialog box on a form and it crashes when the mouse moves over a scroll bar?
0
 
Mohit VijayCommented:
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
 
classnetAuthor Commented:
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
 
CimperialiCommented:
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
 
CimperialiCommented:
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
 
classnetAuthor Commented:
The path was the issue...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now