Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

BUG: Cant choose dates on a DatePicker that fall outside a floating VSTO Add-In

$
0
0

Logged the issue with Microsoft here - the Repro is available for download: https://connect.microsoft.com/VisualStudio/feedback/details/741454/value-change-event-doesnt-fire-for-datetimepicker-controls-used-in-vsto-add-ins

If you put a DateTimePicker in a Excel VSTO floating Add-In and position it so when the calendar drops down, it is outside the edge of the add-in, see here:

enter image description here

Choosing any of the dates circled in the green works as expected, but when clicking any dates circled in red, it just closes the calendar drop down and doesn't set the date!

Does anyone know how I can fix this?

EDIT

This SO user has experienced the problem using WPF: VSTO WPF ContextMenu.MenuItem Click outside a TaskPane not raised

enter image description here

The answer to that question shows the issue was reported to connect a while back but still no solution with VSTO 4.0 SP1: https://connect.microsoft.com/VisualStudio/feedback/details/432998/excel-2007-vsto-custom-task-pane-with-wpf-context-menu-has-focus-problems

One of the workarounds is to use the DispatcherFrame to pump messages and subscribe to GotFocusEvent and LostFocusEvent for the menu. http://blogs.msdn.com/b/vsod/archive/2009/12/16/excel-2007-wpf-events-are-not-fired-for-items-that-overlap-excel-ui-for-wpf-context-menus.aspx but this is all WPF code for menu's not a solution for Winform DateTimePicker.

Repro for Microsoft Connect:

New Project > Excel 2010 Add-In using TaskPane; using Microsoft.Office.Core;

namespace ExcelAddIn2 { public partial class ThisAddIn { TaskPaneView MyTaskView = null; Microsoft.Office.Tools.CustomTaskPane MyTaskPane = null;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    //setup custom taskpane
    MyTaskView = new TaskPaneView();
    MyTaskView.currentInstance = Globals.ThisAddIn.Application;
    MyTaskPane = this.CustomTaskPanes.Add(MyTaskView, "MyTaskView");
    MyTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionFloating;
    MyTaskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
    MyTaskPane.Visible = true;
}
}

File Menu > Add > New Project > Class Library > named TaskPane

Then in the TaskPane project create a User Control called TaskPaneView

public partial class TaskPaneView : UserControl
{
    public TaskPaneView()
    {
        InitializeComponent();
    }

    public Microsoft.Office.Interop.Excel.Application currentInstance { get; set; }

    public TaskPaneCtrl getTaskPaneCtrl
    {
        get { return this.taskPaneCtrl1; }
    }  

}

Next create a User Control with a DateTimePicker, make sure the Calendar control is located toward the bottom right of the user control

public partial class TaskPaneCtrl : UserControl
{
public TaskPaneCtrl()
{
    InitializeComponent();
}
}

In the TaskPane class library Reference the Excel Interop (eg c:\Program Files x86\Microsoft Visual Studio 14.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll).

Build the solution. Commenting out parts that dont work. Build Solution.

Now drag and drop the TaskPaneCtrl onto the TaskPaneView and uncomment thing that failed to compile.

enter image description here

F5 and click the Calendar Control, now try to select a date that is outside the taskpane area. No Value Change event fires, it behaves like a click outside the calendar!

Note: I tried a drop downlist that falls off the control but its events DO FIRE!


Viewing all articles
Browse latest Browse all 88854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>