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

Exception has been thrown by the target of an invocation.

3 Answers 245 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ryan farquhar
Top achievements
Rank 1
Ryan farquhar asked on 13 Jan 2009, 08:57 PM
I keep getting this error, sometimes everytime I run the gridview, sometimes it won't throw the error and it will show the results. Here is my code.

 

 

Dim DS_Assets As DataSet  
 
 
 
sqlQuery = "SELECT location.location_id, location.site_id, location.description, location.code, location.site_id, " & _  
 
 
"asset.asset_tag, asset.serial_number, asset.item_id, asset.date_updated, " & _  
 
 
"item.description " & _  
 
 
"FROM location INNER JOIN asset ON location.location_id = asset.location_id INNER JOIN item ON asset.item_id = item.item_id " & _  
 
 
"WHERE location.site_id=" & Site  
 
 
 
DS_Assets = common.DBConnect(sqlQuery, "assets", activeDBServer, activeDBName, activeDBUser, activeDBPass) ' This is the function that returns the Dataset  
 
 
 
Me.RadGridView1.MasterGridViewTemplate.Columns.Clear()  
 
Me.RadGridView1.MasterGridViewTemplate.GroupByExpressions.Clear()  
 
Me.RadGridView1.MasterGridViewTemplate.SortExpressions.Clear()  
 
Me.RadGridView1.MasterGridViewTemplate.AllowAddNewRow = False 
 
 
Me.RadGridView1.MasterGridViewTemplate.AutoGenerateColumns = False 
 
 
Me.RadGridView1.MasterGridViewTemplate.EnableGrouping = False 
 
   
 
 
Me.RadGridView1.DataSource = DS_Assets.Tables(0)  
 
 
 

The error is thrown on the last line when I try to bind the data to the gridview. There are about 3300 rows in the data being returned. If I look at the inner exception it is returning "NullReferenceException: Object reference not set to an instance of an object."

But the data is there, the Dataset is correct. I have run this code on a regular GridView control and it works fine. Just won't work on the RadGridView. Any ideas what I am doing wrong?

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 19 Jan 2009, 04:01 PM
Hi Ryan farquhar,

I was not able to reproduce the issue. Therefore, please send me a sample project in your support ticket regarding the same topic. This will allow me to help you further.

Best wishes,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
tblack1100
Top achievements
Rank 1
answered on 13 Jun 2011, 08:10 PM
Hello Ryan,

I'm having the same issue and wondered if you ever resolved this issue.



Regards,

Tim
0
Nikolay
Telerik team
answered on 15 Jun 2011, 11:22 AM
Hi tblack1100,

The issue that Ryan experienced was related to the specific implementation of this application. In short, he was trying to populate RadGridView in a separate thread. Here is our answer regarding this scenario:

"RadControls for WinForms are not thread safe. Therefore, you cannot apply operations like databinding in another thread. It is not predictable how RadGridView will behave in such scenario. Although DataGridView may not throw an exception, the scenario of data-binding a control to a datasource in another thread is not quite correct. Instead, you can prepare the datasource in another thread and bind RadGridView in the main thread. In this case, you should make sure that the data source is locked in the main thread (i.e. the method in the other thread has finished its execution) before assigning it to a control."

Regards,
Nikolay
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Ryan farquhar
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
tblack1100
Top achievements
Rank 1
Share this question
or