none
Having trouble with an OpenFileDialog and a RibbonDropDown...Is this a bug? RRS feed

  • Question

  • Hi,

    I'm using VS2008 Professional Edition SP1, Office 2007 SP2, .NET Framework 3.5 and Windows XP SP3.

    Here's how to repeat my problem:

    1. Create an Excel 2007 workbook solution.

    2. Add a ribbon (visual designer) with: ControlIdType=Custom, KeyTip=Z.

    3. Add a RibbonDropDown to the ribbon with: Name=CompaniesDropDown, KeyTip=C.

    Import the following namespaces:

    Imports Microsoft.Office.Tools.Ribbon
    Imports System.Windows.Forms
    
    Add the following code to the ribbon's Load event handler:

        Debug.Print("*** Testing ***")
    
        Try
          Dim company As RibbonDropDownItem
          For c As Integer = 1 To 5
            company = New RibbonDropDownItem
            company.Label = "Company " & c
            CompaniesDropDown.Items.Add(company)
          Next
        Catch ex As Exception
          Debug.Print(ex.Message)
        End Try
    
    

    Add the following code to the drop down SelectionChanged event handler:

        Try
          Dim openFile As New OpenFileDialog
          Dim result As DialogResult = openFile.ShowDialog()
          Debug.Print(result.ToString)
        Catch ex As Exception
          Debug.Print(ex.Message)
        End Try
    
    

    When I use the mouse to select a company from the drop down box, the dialog opens and things work OK. However, if I use the KeyTips the dialog shows and immediately closes, yielding a result of Cancel.

    What I'm I doing wrong?

    Kind regards,

    Carlos Mallen

    Friday, July 1, 2011 7:49 PM

Answers

  • Hi Carlos

    My test environment: VS 2008, Excel 2007 SP2, Windows Vista

    I'm not sure you're doing anything wrong, as such. Have you checked the messages Debug.Print is writing? If I STEP through the code using the keytips I see the following errors, triggered by ShowDialog, so it never gets to printing "Cancel":

    A first chance exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll
    A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in System.Windows.Forms.dll

    Then the actual Exception.Message is: External component has thrown an exception.

    Testing a bit further, it appears that only using the keyboard to confirm the selection in the dropdown is causing the problem. If I use the keyboard up to that point, then click on the entry I want using the mouse, there's no error.

    I'm guessing that the keyboard action is still being run through the system when the dialog box is showing. If you're not seeing the errors I'm getting, our systems probably aren't working at the same speed. So on your machine the keyboard is "pressing" the default button ("Cancel") while on mine it's causing an Access violation because it's being received while the display of the dialogbox is at a different stage (my system is probably a little faster).

    this is further supported by the fact that, if I press the Spacebar rather than Enter or Tab the dialog box displays correctly - the spacebar isn't passing a command that's changing the state of the dialogbox.

    I'm able to almost get it to work, while in Debug mode, by putting a breakpoint at the very beginning of the event handler and Application.DoEvents at the beginning and before each operation with the OpenFileDialog. If I press F5 at the breakpoint, everything runs through correctly. But as soon as I take away the breakpoint, the same error occurs. Putting DoEvents into a loop, to give more time for things to process, also didn't help. The problem remains.

    This appears to be a bug. I urge you to report it on Connect, provide a link to this discussion, and post the URL to your connect bug here so that we can vote on it.


    Cindy Meister, VSTO/Word MVP
    Saturday, July 2, 2011 11:11 AM
    Moderator

All replies

  • Hi Carlos

    My test environment: VS 2008, Excel 2007 SP2, Windows Vista

    I'm not sure you're doing anything wrong, as such. Have you checked the messages Debug.Print is writing? If I STEP through the code using the keytips I see the following errors, triggered by ShowDialog, so it never gets to printing "Cancel":

    A first chance exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll
    A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in System.Windows.Forms.dll

    Then the actual Exception.Message is: External component has thrown an exception.

    Testing a bit further, it appears that only using the keyboard to confirm the selection in the dropdown is causing the problem. If I use the keyboard up to that point, then click on the entry I want using the mouse, there's no error.

    I'm guessing that the keyboard action is still being run through the system when the dialog box is showing. If you're not seeing the errors I'm getting, our systems probably aren't working at the same speed. So on your machine the keyboard is "pressing" the default button ("Cancel") while on mine it's causing an Access violation because it's being received while the display of the dialogbox is at a different stage (my system is probably a little faster).

    this is further supported by the fact that, if I press the Spacebar rather than Enter or Tab the dialog box displays correctly - the spacebar isn't passing a command that's changing the state of the dialogbox.

    I'm able to almost get it to work, while in Debug mode, by putting a breakpoint at the very beginning of the event handler and Application.DoEvents at the beginning and before each operation with the OpenFileDialog. If I press F5 at the breakpoint, everything runs through correctly. But as soon as I take away the breakpoint, the same error occurs. Putting DoEvents into a loop, to give more time for things to process, also didn't help. The problem remains.

    This appears to be a bug. I urge you to report it on Connect, provide a link to this discussion, and post the URL to your connect bug here so that we can vote on it.


    Cindy Meister, VSTO/Word MVP
    Saturday, July 2, 2011 11:11 AM
    Moderator
  • Thanks a lot for your time Cindy.

    In my computer the result of Debug.Print is Cancel. No error occurs.

    Regarding Connect, I'm not able to find a site for Visual Studio Tools for Office, is it OK if I post this issue in the Visual Studio 2010 site? If not, which is the appropriate site?

    Kind regards,

    Carlos Mallen

    Monday, July 4, 2011 2:16 PM
  • Hi Carlos

    Yes, the Visual Studio 2010 site is the correct one :-)


    Cindy Meister, VSTO/Word MVP
    Monday, July 4, 2011 2:39 PM
    Moderator
  • Here's the link to Connect:

    https://connect.microsoft.com/VisualStudio/feedback/details/678303/having-trouble-with-an-openfiledialog-and-a-ribbondropdown-is-this-a-bug

    All the best!

    Carlos Mallen

    Monday, July 4, 2011 5:42 PM
  • thanks! I've voted and added a comment.
    Cindy Meister, VSTO/Word MVP
    Tuesday, July 5, 2011 7:26 AM
    Moderator