我SELECT id,NAME,username,customfield FROM users WHERE Id=2
绑定了ListObject
,如How to: Add ListObject Controls to Worksheets中所述。我想在输入每一行时计算某些列值。
示例:
如何在当前单元失去焦点时使表更新DataSet
?
答案 0 :(得分:0)
您可以使用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;
答案 1 :(得分:0)
我认为最好使用ListObject.Change事件而不是WorkSheet.Change事件,因为参数会告诉您ListObject在哪个范围内 进行更改,从而避免了其他所有更改事件从工作表的其余部分开始:
private void ListObject_Change_event(targetRange As Range, changedRanges As ListRanges)