//************************************************************************* // Method: OnAutoFillWorkbookClick() // /// <summary> /// Handles the Click event on the btnAutoFillWorkbook button. /// </summary> /// /// <param name="mode"> /// Indicates the mode in which the AutoFillWorkbookDialog is being used. /// </param> /// /// <remarks> /// This method can be called from outside the class to simulate a button /// click. /// </remarks> //************************************************************************* public void OnAutoFillWorkbookClick( AutoFillWorkbookDialog.DialogMode mode ) { AssertValid(); this.ThisWorkbook.AutoFillWorkbook(mode); }
//************************************************************************* // Method: AutoFillWorkbook() // /// <summary> /// Shows the dialog that fills edge and vertex attribute columns using /// values from user-specified source columns. /// </summary> /// /// <param name="mode"> /// Indicates the mode in which the AutoFillWorkbookDialog is being used. /// </param> //************************************************************************* public void AutoFillWorkbook( AutoFillWorkbookDialog.DialogMode mode ) { AssertValid(); if ( !this.ExcelApplicationIsReady(true) ) { return; } AutoFillWorkbookDialog oAutoFillWorkbookDialog = new AutoFillWorkbookDialog(this.InnerObject, mode); Int32 iHwnd = this.Application.Hwnd; oAutoFillWorkbookDialog.WorkbookAutoFilled += delegate { this.Ribbon.OnWorkbookAutoFilled( ( new GeneralUserSettings() ).AutoReadWorkbook ); }; oAutoFillWorkbookDialog.Closed += delegate { // Activate the Excel window. // // This is a workaround for an annoying and frustrating bug // involving the AutoFillWorkbookDialog when it runs modeless. If // the user takes no action in AutoFillWorkbookDialog before // closing it, the Excel window gets activated when // AutoFillWorkbookDialog closes, as expected. However, if he // opens one of AutoFillWorkbookDialog's modal dialogs, such as // NumericRangeColumnAutoFillUserSettingsDialog, and then closes // the modal dialog and AutoFillWorkbookDialog, some other // application besides Excel gets activated. // // Setting the owner of the modal dialog to the Excel window // (this.Application.Hwnd) didn't help. Neither did setting the // owner of the modal dialog to AutoFillWorkbookDialog. Nothing // worked except explicitly activating the Excel window when the // AutoFillWorkbookDialog closes. Win32Functions.SetForegroundWindow( new IntPtr(iHwnd) ); }; if (mode == AutoFillWorkbookDialog.DialogMode.Normal) { oAutoFillWorkbookDialog.Show( new Win32Window(iHwnd) ); } else { oAutoFillWorkbookDialog.ShowDialog(); } }