none
Excel-VSTO-AddIn, CustomTaskPane keeps input focus when typing in spreasheet RRS feed

  • Question

  • Hello,

    I created a simple CustomTaskPane to make browsing my workbooks easier.
    The underlying UserControl contains one tab for each worksheet in the activeWorkbook.
    A MouseClick on a tab activates the corresponding sheet.

    My problem is the following:

    When I MouseClick a tab, the correspongding worksheet is properly activated.
    However, if I then click a cell on the worksheet, the worksheet doesn't have the input focus.
    I mean that typing anything has no effect at all on the content of the worksheet.
    Trying several times to input some data in other cells, often fails, but not always.
    Activating some arbitrary tab of the Excel Ribbons unfreezes this input problem.
    In the same way, the formula bar still works properly.

    This looks like cliking on a worksheet doesn't remove the input forcus from the CustomTaskPane and doesn't bring it to the worksheet.

    Could you help me understand what might happen and how I could solve this problem?

    Thanks,

    Michel

    Monday, August 5, 2013 10:12 AM

Answers

  • Hi Michel,

    I failed to reproduce your issue on my lab machine (Office 2013).

    Here are my steps:

    First, I click “Sheet2” button to activate Sheet 2 and Sheet 2 is activated.

    Then, I click a cell in the activated sheet, and input “Text”, I tried it several times and did not encounter the issue you mentioned above.

    Below is my code:

    namespace ExcelAddIn
    {
        public partial class CustomTaskPane : UserControl
        {
            public CustomTaskPane()
            {
                InitializeComponent();
            }
    
    
            private void button1_Click(object sender, EventArgs e)
            {
                var wk = Globals.ThisAddIn.Application.ActiveWorkbook;
    
                var sheet = wk.Sheets[1] as Worksheet;
    
                sheet.Activate();
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                var wk = Globals.ThisAddIn.Application.ActiveWorkbook;
    
                var sheet = wk.Sheets[2] as Worksheet;
    
                sheet.Activate();
            }
        }
    }

    Would you please tell me which version of Office you are currently using and post some of your code so that I can try it on my side?



    Jeffrey Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Lalbatros Tuesday, August 6, 2013 10:56 AM
    Tuesday, August 6, 2013 6:49 AM
    Moderator

All replies

  • Hi Michel,

    I failed to reproduce your issue on my lab machine (Office 2013).

    Here are my steps:

    First, I click “Sheet2” button to activate Sheet 2 and Sheet 2 is activated.

    Then, I click a cell in the activated sheet, and input “Text”, I tried it several times and did not encounter the issue you mentioned above.

    Below is my code:

    namespace ExcelAddIn
    {
        public partial class CustomTaskPane : UserControl
        {
            public CustomTaskPane()
            {
                InitializeComponent();
            }
    
    
            private void button1_Click(object sender, EventArgs e)
            {
                var wk = Globals.ThisAddIn.Application.ActiveWorkbook;
    
                var sheet = wk.Sheets[1] as Worksheet;
    
                sheet.Activate();
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                var wk = Globals.ThisAddIn.Application.ActiveWorkbook;
    
                var sheet = wk.Sheets[2] as Worksheet;
    
                sheet.Activate();
            }
        }
    }

    Would you please tell me which version of Office you are currently using and post some of your code so that I can try it on my side?



    Jeffrey Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Lalbatros Tuesday, August 6, 2013 10:56 AM
    Tuesday, August 6, 2013 6:49 AM
    Moderator
  • Thanks a lot, Jeffrey.

    I am using Office 2010, VS-2010-Pro.

    Based on your input, I will investigate what might go wrong in my own code, which is more complicated than what I suggested.

    I do intercept a few events, and this "workbook brower" I created allows deleting sheets, moving sheets, changing names, and collapsing chapters (bunch of sheets). Therefore, it is likely that there is some interaction between some event processing.

    I also do not use regular buttons, but a simple usercontrol (my tabs) that intercepts a few event too.

    Also, the Application.SheetActivate event refreshes my CustomTaskPane (to show the highligh the selected sheet). 

    Finally, the CustomTaskPane is filled automatically with these tabs and refreshed when the active workbook changes.

    Would you have some advise about how to pinpoint the cause of my problem (debugging)?
    I already considered spying events, since I am not able to understand why and when the normal behaviour occurs.

    I will post the result, or more questions, or some code if possible.

    Thanks again,

    Michel



    • Edited by Lalbatros Tuesday, August 6, 2013 7:53 AM
    Tuesday, August 6, 2013 7:48 AM
  • Hello Jeffrey,

    I tried your sample code in Excel-VSTO 2012, and it work correctly.
    I will look for the source of the problem in my full code.

    Michel

    Tuesday, August 6, 2013 9:52 AM
  • Hello again Jeffrey,

    I found out the origin of the problem.
    I used a MouseHookListener to detect user clicks on any Chart within any worksheet.
    (the Application.SheetSelectionChange does not detect when a Chart is selected).
    Disabling this MouseHookListener solved my problem simply.

    Unfortunately, this leaves me without a method to detect when Chart is selected, which is something I need for my application.
    If you had some suggestion for this, it would help me a lot.

    Thanks again,

    Michel



    • Edited by Lalbatros Tuesday, August 6, 2013 10:32 AM
    Tuesday, August 6, 2013 10:25 AM