This is a migrated thread and some comments may be shown as answers.

Getting System.Reflection.TargetInvocationException error when setting datasource

3 Answers 241 Views
GridView
This is a migrated thread and some comments may be shown as answers.
AaronP
Top achievements
Rank 1
AaronP asked on 10 Nov 2010, 07:07 PM
I updated to version 2010.3.10.1109 from 2010.2.10.914 and when I set the datasource I now get TargetInvocationException
"Exception has been thrown by the target of an invocation.".  It was working fine in the previous version.

Any ideas?

Thank you,
Aaron

3 Answers, 1 is accepted

Sort by
0
AaronP
Top achievements
Rank 1
answered on 10 Nov 2010, 08:33 PM
I found that I needed to wrap my grid setup with a DeferRefresh() method like:

using (gridView.DeferRefresh())
{
     gridView.DataSource = estimatingDataSet;
     gridView.DataMember = "vMOParentItemList";
     // Setup of grid...
}

Is this new to 2010 Q3, or should I have been doing this before?
0
Emanuel Varga
Top achievements
Rank 1
answered on 10 Nov 2010, 11:44 PM
Hello Aaron,

Sadly i haven't yet updated to the latest version, i will do that tomorrow as fast as possible, but first thing, there is no DeferRefresh property in the Q2 version.
Second, you could try setting stepping into the property, maybe some other event fires before throwing the exception, or please post here the stacktrace.
Alternatively you could try wrapping these lines with BeginUpdate(), EndUpdate().

This will also help with performance of the grid.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

WinForms MVP
0
Julian Benkov
Telerik team
answered on 15 Nov 2010, 05:56 PM
Hi Aaron,

The DeferRefresh method was included for the collections that can suspend/resume update notifications. The DeferRefresh is also added to RadGridView and GridViewTemplate. The logic of the DeferRefresh method is the same as the logic of BeginUpdate/EndUpdate called internally in DeferRefresh. This method was added to help you to achieve elegant code where you need to execute a batch update operation.

As to the exception - if your code has worked before without using DeferRefresh or BeginUpdate/EndUpdate, this most probably means that we have introduced an issue in your scenario. Please open a new ticket and send us a sample application which demonstrates your case. This will allow us to assist you further.

Emanuel, thank you for your comments.

Kind regards,
Julian Benkov
the Telerik team
See What's New in RadControls for WinForms in Q3 2010 on Wednesday, November 17, 11am Eastern Time: Register here>>
Tags
GridView
Asked by
AaronP
Top achievements
Rank 1
Answers by
AaronP
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or