2
votes

I created a simple AddIn for MS Excel, but having a problem with the Custom Task Pane.

Custom Task Pane control is written in WPF, but whenever user tries to input some data to the textbox field in CTP which he previously selected with the mouse, Excel steels the focus and return it to the selected cell.

Can I prevent this behavior?

The solution that user need to apply is to press "Esc" button on the keyboard, and than he can again select the input control in the CTP and write to it.

The same happens with controls that are having context menus. When user clicks on the control with right mouse button, context menu is shortly visible and focus is returned to the Excel Worksheet.

If user is actively editing some cell than he can't select the neither of controls in CTP before finishing edit but can access the ribbon buttons.

Please, point me to the existing solutions if applicable.

1
In my current implementation I had to create the task pane on a different thread. This meant that when the focus was on the pane excel did not attempt to handle to keypresses.Stephen Ross
I hoped that I missed some API call, but nevertheless thanks for the comment, I'll try the solution. We certainly need to use some tricks here and there when developing Office plugins.Beaver

1 Answers

0
votes

@beaver - When all controls are disabled on any of Pane windows, Excel secretly steals the focus; ending up in an ALT key pressed. To remedy this situation; ALT then ESC key press.

In the class..

Using System.Windows.Forms;

....
After the procedure that leaves no controls focused

SendKeys.Send("%");
SendKeys.SendWait("{ESC}");

[optional but highly recommended for better performance]
....
in your App.config

<configuration>
  <appSettings>
    <add key="SendKeys" value="SendInput"/>
  </appSettings>
...