我有一个 ListObject
绑定(bind)到 DataSet
如 How to: Add ListObject Controls to Worksheets 中所述.我想在输入每一行时计算某些列值。
例子:
如何使表更新
DataSet
当前单元格失去焦点?
最佳答案
您可以使用 SheetTableUpdate
事件以捕获列表对象中的更改。
public partial class ThisAddIn
{
public static Excel.Application e_application;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
e_application = this.Application;
e_application.SheetTableUpdate += new Excel.AppEvents_SheetTableUpdateEventHandler(e_Application_SheetTableUpdate_Event);
}
private void e_Application_SheetTableUpdate_Event(object sender, Excel.TableObject target)
{
//--sender object refers to active sheet and must be cast as Worksheet before use
//Update your dataset here
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
e_application.SheetTableUpdate -= new Excel.AppEvents_SheetTableUpdateEventHandler(e_Application_SheetTableUpdate_Event);
e_application = null;
}
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new Ribbon();
}
}
您可以引用
ActiveCell
通过使用以下代码。(Excel.Range)Application.ActiveCell;
关于c# - 如何在 Excel 中的 ListObject 绑定(bind)中触发更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45807992/