Suresh3594
New Member
- Joined
- Jul 5, 2017
- Messages
- 7
[FONT="]Hi,[/FONT]
[FONT="]I am working on vsto addin which uses ListObject to create table. This ListObject is binded to a List<> collection and the data shows up fine. The problem is, when user adds a new row in the table by using Right Click->Insert->Table Row Above/Below, It does not add a new entry in datasource. To fix this, I am handling worksheet change event and then check if new row is inserted or not. If its inserted, I will Undo the change and I am adding a new entry in the List<> datasource. [/FONT]
[FONT="]This is how I am doing it:
[/FONT]
[FONT="]For some reason, SetDataBinding is failing and it throws error. This is the error[/FONT]
[FONT="]System.Runtime.InteropServices.COMException was unhandled by user code
HResult=-2146827864
Message=Exception from HRESULT: 0x800A01A8
Source=mscorlib
ErrorCode=-2146827864
StackTrace:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.ListObject.get_Range()
at Microsoft.Office.Tools.Excel.ListObjectImpl.get_Range()
at Microsoft.Office.Tools.Excel.ResizeHandler.InitializeState(Int32 dataRowCount, Int32 dataColumnCount, Boolean& needsNoRowsFix, Boolean& needsOneRowFix)
at Microsoft.Office.Tools.Excel.ResizeHandler.Resize(Int32 dataRowCount, Int32 dataColumnCount, Boolean insertOrRemoveRanges)
at Microsoft.Office.Tools.Excel.ResizeHandler.Resize(ListObjectImpl listObject, Worksheet worksheet, Int32 dataRowCount, Int32 dataColumnCount, Boolean insertOrRemoveRanges)
at Microsoft.Office.Tools.Excel.ListObjectImpl.Resize(Int32 rows, Int32 columns)
at Microsoft.Office.Tools.Excel.ListObjectImpl.SetItemsCore(Boolean checkTypeChanged, Boolean force)
at Microsoft.Office.Tools.Excel.ListObjectImpl.SetDataConnection(Object newDataSource, String newDataMember, String[] newMappedColumns, Boolean force)
at Microsoft.Office.Tools.Excel.ListObjectImpl.SetDataConnection(Object newDataSource, String newDataMember, Boolean force)
at Microsoft.Office.Tools.Excel.ListObjectImpl.SetDataBinding(Object dataSource)
at MyProject.Addin.OnSelectionChange(Range target)[/FONT]
[FONT="]I am working on vsto addin which uses ListObject to create table. This ListObject is binded to a List<> collection and the data shows up fine. The problem is, when user adds a new row in the table by using Right Click->Insert->Table Row Above/Below, It does not add a new entry in datasource. To fix this, I am handling worksheet change event and then check if new row is inserted or not. If its inserted, I will Undo the change and I am adding a new entry in the List<> datasource. [/FONT]
[FONT="]This is how I am doing it:
[/FONT]
Code:
[COLOR=#000000]vstoListObject[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Disconnect[/COLOR][COLOR=#666600]();[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#660066]Globals[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]ThisAddIn[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Application[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Undo[/COLOR][COLOR=#666600]();[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000088]var[/COLOR][COLOR=#000000] newEntry [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000088]new[/COLOR][COLOR=#000000] [/COLOR][COLOR=#660066]MyClassObject[/COLOR][COLOR=#666600]();[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#660066]DataSource[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Insert[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]index[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000] newEntry[/COLOR][COLOR=#666600]);[/COLOR][COLOR=#000000]
vstoListObject[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]SetDataBinding[/COLOR][COLOR=#666600]([/COLOR][COLOR=#660066]DataSource[/COLOR][COLOR=#666600]);[/COLOR]
[FONT="]For some reason, SetDataBinding is failing and it throws error. This is the error[/FONT]
[FONT="]System.Runtime.InteropServices.COMException was unhandled by user code
HResult=-2146827864
Message=Exception from HRESULT: 0x800A01A8
Source=mscorlib
ErrorCode=-2146827864
StackTrace:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.ListObject.get_Range()
at Microsoft.Office.Tools.Excel.ListObjectImpl.get_Range()
at Microsoft.Office.Tools.Excel.ResizeHandler.InitializeState(Int32 dataRowCount, Int32 dataColumnCount, Boolean& needsNoRowsFix, Boolean& needsOneRowFix)
at Microsoft.Office.Tools.Excel.ResizeHandler.Resize(Int32 dataRowCount, Int32 dataColumnCount, Boolean insertOrRemoveRanges)
at Microsoft.Office.Tools.Excel.ResizeHandler.Resize(ListObjectImpl listObject, Worksheet worksheet, Int32 dataRowCount, Int32 dataColumnCount, Boolean insertOrRemoveRanges)
at Microsoft.Office.Tools.Excel.ListObjectImpl.Resize(Int32 rows, Int32 columns)
at Microsoft.Office.Tools.Excel.ListObjectImpl.SetItemsCore(Boolean checkTypeChanged, Boolean force)
at Microsoft.Office.Tools.Excel.ListObjectImpl.SetDataConnection(Object newDataSource, String newDataMember, String[] newMappedColumns, Boolean force)
at Microsoft.Office.Tools.Excel.ListObjectImpl.SetDataConnection(Object newDataSource, String newDataMember, Boolean force)
at Microsoft.Office.Tools.Excel.ListObjectImpl.SetDataBinding(Object dataSource)
at MyProject.Addin.OnSelectionChange(Range target)[/FONT]