I'm implementing the code from the book to create a customized action pane in Excel
using System;
using System.Data; using System.Drawing; using System.Windows.Forms; using Microsoft.VisualStudio.OfficeTools.Interop.Runtime; using Excel = Microsoft.Office.Interop.Excel; using Office = Microsoft.Office.Core;
namespace ExcelWorkbook1 { public partial class Sheet1 { public Button customerButton = new Button(); public Button inventoryButton = new Button();
private void Sheet1_Startup(object sender, EventArgs e)
{
customerButton.Text = "Select a customer...";
inventoryButton.Text = "Check inventory...";
this.orderInfo.Selected +=
new Excel.DocEvents_SelectionChangeEventHandler(
OrderInfo_Selected);
this.orderInfo.Deselected +=
new Excel.DocEvents_SelectionChangeEventHandler(
OrderInfo_Deselected);
this.customerInfo.Selected +=
new Excel.DocEvents_SelectionChangeEventHandler(
CustomerInfo_Selected);
this.customerInfo.Deselected +=
new Excel.DocEvents_SelectionChangeEventHandler(
CustomerInfo_Deselected);
}
#region VSTO Designer generated code
private void InternalStartup()
{
this.Startup += new System.Event开发者_StackOverflowHandler(Sheet1_Startup);
}
#endregion
void OrderInfo_Selected(Excel.Range target)
{
Globals.ThisWorkbook.ActionsPane.Controls.Add(inventoryButton);
}
void OrderInfo_Deselected(Excel.Range target)
{
Globals.ThisWorkbook.ActionsPane.Controls.Remove(inventoryButton);
}
void CustomerInfo_Selected(Excel.Range target)
{
Globals.ThisWorkbook.ActionsPane.Controls.Add(customerButton);
}
void CustomerInfo_Deselected(Excel.Range target)
{
Globals.ThisWorkbook.ActionsPane.Controls.Remove(customerButton);
}
} }
However
the code this.order.Selected' is not regconized
Do you have any suggestion for me?
Thanks
Do you have a named range in your Sheet1 with name orderInfo? If yes, is it generated in the code-behind? (Sheet1.Designer.cs)
Notice, that you misspeled the name of your member in the last sentence: should be 'this.orderInfo.Selected'
精彩评论