VB.NET openFileDialog crash

3

I am having issues with calling openFileDialog on button click.

Relevant code:

   Private Sub MemoCp_ButtonClick(sender As Object, e As ButtonPressedEventArgs) Handles MemoCp.ButtonClick
        Dim Editor As ButtonEdit = CType(sender, ButtonEdit)
        Dim Button As EditorButton = e.Button
        If Editor.Properties.Buttons.IndexOf(e.Button).ToString() = 1 Then
            Using ofd As New OpenFileDialog
                ofd.InitialDirectory = "C:\"
                ofd.FileName = ""
                ofd.ShowHelp = True
                ofd.ShowDialog() <-- Program crashes here
                TryCast(sender, ButtonEdit).EditValue = ofd.FileName
            End Using
        End If
    End Sub

I have a form with 2 checkboxes. When I don't select any check box and click the button, it works perfectly, but if i select the checkboxes beforehand and click the button, I get this error:

Exception thrown at 0x769F1DF3 (shell32.dll) in Unos.exe: 0xC0000005: Access violation reading location 0x0000000A.

With this call Stack:

    shell32.dll!CExplorerBrowser::Advise()  Unknown
    comdlg32.dll!CFileOpenSave::_CreateExplorerBrowser()    Unknown
    comdlg32.dll!CFileOpenSave::_InitOpenSaveDialog(struct HWND__ *)    Unknown
    comdlg32.dll!CFileOpenSave::s_OpenSaveDlgProc(struct HWND__ *,unsigned int,unsigned int,long)   Unknown
    user32.dll!__InternalCallWinProc@20()   Unknown
    user32.dll!UserCallDlgProcCheckWow()    Unknown
    user32.dll!DefDlgProcWorker()   Unknown
    user32.dll!_DefDlgProcW@16()    Unknown
    user32.dll!__InternalCallWinProc@20()   Unknown
    user32.dll!UserCallWinProcCheckWow()    Unknown
    user32.dll!DispatchClientMessage()  Unknown
    user32.dll!___fnDWORD@4()   Unknown
    ntdll.dll!_KiUserCallbackDispatcher@12()    Unknown
    user32.dll!InternalCreateDialog()   Unknown
    user32.dll!InternalDialogBox()  Unknown
    user32.dll!_DialogBoxIndirectParamAorW@24() Unknown
    user32.dll!_DialogBoxIndirectParamW@20()    Unknown
    comdlg32.dll!CFileOpenSave::Show(struct HWND__ *)   Unknown
    comdlg32.dll!_InvokeNewFileOpenSave(struct IFileDialog *,unsigned short,struct HWND__ *,struct _OFNINITINFO *,struct HWND__ *)  Unknown
    comdlg32.dll!_CreateNewFileOpenSaveInProc(unsigned short,struct HWND__ *,struct _OFNINITINFO *) Unknown
    comdlg32.dll!NewGetFileName(struct OPENFILEINFO *,int)  Unknown
    comdlg32.dll!_GetFileName@8()   Unknown
    comdlg32.dll!_GetOpenFileNameW@4()  Unknown
    System.Windows.Forms.ni.dll!65f0b4f0()  Unknown
    [Frames below may be incorrect and/or missing, native debugger attempting to walk managed call stack]   Unknown
    [External Code] 
>   Unos.exe!Unos.FormUnos.MemoCp_ButtonClick(Object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) Line 611 Basic
    [External Code] 

I am struggling to fix this for 5 days, if you could help me solve it I would be very grateful! Thanks in advance.

EDIT:

I shortened the form code as much as I could so that the problem still occurs. Here is the entire code of the shortened version:

Imports System.ComponentModel
Imports System.Data.OleDb
Imports System.Text
Imports DevExpress.XtraEditors.Controls

Partial Public Class Form1
    Shared Sub New()
        DevExpress.UserSkins.BonusSkins.Register()
    End Sub
    Public Sub New()
        InitializeComponent()
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Drzave_LookUp()
    End Sub
    Public Sub Drzave_LookUp()


        Dim sqlDrzave As String = "Select Drzave.SifraDrzave, Drzave.Naziv, Drzave.OZNAKA " &
                                " FROM Drzave INNER JOIN Kupci On Drzave.SifraDrzave = Kupci.Drzava " &
                                            " GROUP BY Drzave.SifraDrzave, Drzave.Naziv, Drzave.OZNAKA " &
                                            " ORDER BY Drzave.SifraDrzave "



        Dim DrzaveAdapter As OleDbDataAdapter = New OleDbDataAdapter(sqlDrzave, cn)
        Dim dsKupci As DataSet = New DataSet
        DrzaveAdapter.Fill(dsKupci, "Drzave")

        SearchLookUpEdit1.Properties.DataSource = dsKupci.Tables("Drzave")
        SearchLookUpEdit1.Properties.DisplayMember = "Naziv"
        SearchLookUpEdit1.Properties.ValueMember = "Naziv"
        SearchLookUpEdit1.Properties.BestFitMode = BestFitMode.BestFitResizePopup
        SearchLookUpEdit1.Properties.PopulateViewColumns()


    End Sub
    Private Sub SearchLookUpEdit1_EditValueChanged(sender As Object, e As EventArgs) Handles SearchLookUpEdit1.EditValueChanged
        Objekti_LookUp(SearchLookUpEdit1.EditValue)
    End Sub

    Public Sub Objekti_LookUp(ByVal drzava As String)

        Dim sqlObjekti As String = "SELECT Objekti.SifraObjekta, Objekti.Naziv, Objekti.Adresa, Objekti.Mesto, Objekti.Instalater, Objekti.Drzava " &
                                    " FROM Objekti " &
                                    " WHERE (((Objekti.Drzava)='" & drzava & "')) "

        Dim ObjektiAdapter As OleDbDataAdapter = New OleDbDataAdapter(sqlObjekti, cn)
        Dim dsObjekti As DataSet = New DataSet
        ObjektiAdapter.Fill(dsObjekti, "Objekti")

        SearchLookUpEdit2.Properties.DataSource = dsObjekti.Tables("Objekti")
        SearchLookUpEdit2.Properties.DisplayMember = "SifraObjekta"
        SearchLookUpEdit2.Properties.ValueMember = "SifraObjekta"
        SearchLookUpEdit2.Properties.BestFitMode = BestFitMode.BestFitResizePopup
        SearchLookUpEdit2.Properties.PopulateViewColumns()

    End Sub
    Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
        Dim SelectedFilePath As String = ""
        Using ofd As New OpenFileDialog
            ofd.InitialDirectory = "Z:\"
            ofd.FileName = ""
            ofd.ShowHelp = True
            If ofd.ShowDialog() = DialogResult.OK Then <-- Program crashes here
                SelectedFilePath = ofd.FileName
            End If
        End Using
        Debug.Print(SelectedFilePath)

    End Sub

End Class
.net
vb.net
devexpress
asked on Stack Overflow Jul 4, 2020 by midiland58 • edited Jul 5, 2020 by midiland58

1 Answer

0

This code works fine without whatever 3rd party button you are using. Your problem is probably on the line following the one you indicated. Your problem is not with the OpenFileDialog. Ask a new question that explains what the ButtonEdit and EditorButton are.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim SelectedFilePath As String = ""
    Using ofd As New OpenFileDialog
        ofd.InitialDirectory = "C:\"
        ofd.FileName = ""
        ofd.ShowHelp = True
        If ofd.ShowDialog() = DialogResult.OK Then
            SelectedFilePath = ofd.FileName
        End If
    End Using
    Debug.Print(SelectedFilePath)
End Sub
answered on Stack Overflow Jul 4, 2020 by Mary

User contributions licensed under CC BY-SA 3.0