i set a data source (data table ) to the grid with the line
DataGrid.DataSource = dt;
then i save some staff in my DB and then i wanted to bound different data table to the same grid using the same command line
DataGrid.DataSource = saveddt;
but i get a null reference exception
Object reference not set to an instance of an object.
at Telerik.WinControls.UI.GridTableBodyElement.editor_Validated(Object sender, EventArgs e)\r\n at Telerik.WinControls.UI.RadCheckBoxEditor.OnValidated(EventArgs args)\r\n at Telerik.WinControls.UI.RadCheckBoxEditor.SaveValue()\r\n at Telerik.WinControls.UI.GridTableBodyElement.ResetActiveEditor(Boolean restoreOriginalValue)\r\n at Telerik.WinControls.UI.GridTableBodyElement.Update(Boolean dataSourceChanged)\r\n at Telerik.WinControls.UI.GridTableElement.Update(Boolean dataSourceChanged)\r\n at Telerik.WinControls.UI.GridViewInfo.UpdateView(Boolean dataSourceChanged)\r\n at Telerik.WinControls.UI.GridViewInfo.UpdateView()\r\n at Telerik.WinControls.UI.GridViewTemplate.Rebind()\r\n at Telerik.WinControls.UI.RadGridView.RefreshColumnsAndRows()\r\n at Telerik.WinControls.UI.GridViewData.InitDataOnly()\r\n at Telerik.WinControls.UI.GridViewData.InitView()\r\n at Telerik.WinControls.UI.GridViewData.SetDataConnection(Object dataSource, String dataMember)\r\n at Telerik.WinControls.UI.RadGridView.DoDataBinding()\r\n at Telerik.WinControls.UI.RadGridView.CallDoDataBinding()\r\n at Telerik.WinControls.UI.GridViewTemplate.set_DataSource(Object value)\r\n at Telerik.WinControls.UI.RadGridView.set_DataSource(Object value)\r\n
14 Answers, 1 is accepted
we can't reproduce the reported problem with the latest SP2 release. RadGridView works fine when changing the DataSource in run-time. Please, open a support ticket and send us a example with your scenario so that we can review it locally.
Sincerely yours,
Julian Benkov
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

We will ask you to open a support ticket and send us a example with your scenario so that we can review it locally. We did not get Yarik's project, so we are still in the dark what is going on. I would like to confirm that we can't reproduce the reported problem with the latest SP2 release and that RadGridView works fine when changing the DataSource in run-time.
Thank you for your understanding.
All the best,
Julian Benkov
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

I did add detail about this bug in a support ticket I have open.
Let me be more specific for other poor users out there who may be suffering from the same problem.
If I have a column which is a "checkbox column", and I click a checkbox (which also selects the row), and then I bind a new datasource to the grid, I get the exception. This is using Sp2.
(also, I can't get the format code block toolstrip item to work on this forum. I click it and get an empty radwindow object?)
Here is a really simple form u can try this with. (just create a form with a rad grid and button and hook up events)
Imports Telerik.WinControls.ui
Public Class Form1
Dim colFileName As GridViewTextBoxColumn
Dim colUpgradeName As GridViewBooleanColumn
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RadGridView1.DataSource = GetCollection()
End Sub
Private Sub AddColumns()
colFileName = New GridViewTextBoxColumn
colFileName.DataField = "FileName"
colFileName.HeaderText = "File Name"
colFileName.ReadOnly = True
RadGridView1.MasterGridViewTemplate.Columns.Add(colFileName)
colUpgradeName = New GridViewBooleanColumn
colUpgradeName.HeaderText = "New / Updated"
colUpgradeName.DataField = "Upgrade"
RadGridView1.MasterGridViewTemplate.Columns.Add(colUpgradeName)
End Sub
Private Function GetCollection() As List(Of ReleaseFileInfo)
Dim list As New List(Of ReleaseFileInfo)
Dim file1 As New ReleaseFileInfo
file1.FileName = "aaa"
file1.Upgrade = False
list.Add(file1)
Dim file2 As New ReleaseFileInfo
file2.FileName = "aaa"
file2.Upgrade = False
list.Add(file2)
Return list
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddColumns()
End Sub
End Class
Public Class ReleaseFileInfo
Private _fileName As String
Public Property FileName() As String
Get
Return _fileName
End Get
Set(ByVal value As String)
_fileName = value
End Set
End Property
Private _upgrade As Boolean
Public Property Upgrade() As Boolean
Get
Return _upgrade
End Get
Set(ByVal value As Boolean)
_upgrade = value
End Set
End Property
End Class

In the example, if i set it to "Readonly", the rebind works.
Even funnier than that, if I click on the checkbox, I doesn't toggle the value, but if I click in the same column, next to the checkbox, it DOES toggle the value. on a READONLY column.
This is not the first time I've had trouble with that column type. Will this finally be fixed in the next release, because if it isn't then I am going to drop this Grid component once and for all, and try regain my sanity.
We are deeply sorry for this inconvenience. All issues related to boolean column are fixed now and they will be publicly available in our next release (we are expecting the beta no later than Tuesday next week). This beta will contain fixes for the issues you mentioned. We will appreciate it if you share your experience with the new version.
All the best,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

I have a boolean data column in my grid. I'm not even trying to edit that, I'm editing a text box, then switching datasources and then I get the exception.
Update:
My grid has a mix of read only, editable controls, and a boolean column. If I edit the text box, or the boolean column, then click on a read only column, then switch the datasource, then switch the datasource again. That produces the exception. The datasource of the grid becomes nothing and Any attempt to change the datasource after that also fails.
Stack trace of exception:
at Telerik.WinControls.UI.RadGridView.ValidateRowChange(GridViewRowInfo row)
at Telerik.WinControls.UI.GridViewInfo.SetCurrentRow(GridViewRowInfo row, Boolean setPosition, Boolean shift, Boolean control, Boolean rightMouseButton)
at Telerik.WinControls.UI.GridViewTemplate.SetCurrentRow(GridViewRowInfo rowInfo)
at Telerik.WinControls.Data.DataAccessComponent.Bind(Object dataSource, String dataMember)
at Telerik.WinControls.Data.DataAccessComponent.set_DataSource(Object value)
at Telerik.WinControls.UI.RadGridView.set_DataSource(Object value)
at JMInterface.frmWeeklySchedule.SetSchType() in E:\WorkingFolder\JMv6\Interface\frmWeeklySchedule.vb:line 305

ID: 234893
You can find the answer to your question in the support ticket (ID: 234893). Should you have any questions, we will be glad to help.
All the best,
Jack
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

There is indeed an issue with ValidateRowChange method that we will address in our upcoming release. This issue appears when navigating through read-only cells and then changing the data source of RadGridView. You can work around this issue by changing the default grid behavior. You should inherit from BaseGridBehavior and override its OnMouseDownLeft event. Here is a sample:
this.radGridView1.GridBehavior = new MyGridBehavior(); |
public class MyGridBehavior : BaseGridBehavior |
{ |
protected override bool OnMouseDownLeft(MouseEventArgs e) |
{ |
GridDataCellElement cell = this.GridControl.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement; |
if (cell != null |
&& !cell.Equals(this.GridControl.CurrentCell) |
&& cell.RowInfo.Equals(this.GridControl.CurrentRow) |
&& cell.ColumnInfo.ReadOnly) |
{ |
this.GridControl.EndEdit(); |
} |
return base.OnMouseDownLeft(e); |
} |
} |
To solve the issue in case of a checkbox column, you can handle the ValueChanged event:
private void radGridView1_ValueChanged(object sender, System.EventArgs e) |
{ |
if ((sender) is RadCheckBoxEditor) |
{ |
RadGridView1.EndEdit(); |
} |
} |
If the issue appears when the focus is changed between two grids, you can add the following code inside the LostFocus event handler:
void radGridView1_LostFocus(object sender, EventArgs e) |
{ |
this.radGridView1.EndEdit(); |
} |
If this does not help, we will need to review your application to see what else is going on.
Greetings,
Jack
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.


Hello we are experiencing the same problem when rebinding the datasource.
We are not using any checkbox in that grid, only textbox, combobox and datetime.
At one point it get bugged and throws exception all the time...
Can we expect a release soon to fix this problem.
thanks
mateo
The first one is easy. You should just check whether RadGridView contains the focus:
void radGridView1_LostFocus(object sender, EventArgs e) |
{ |
if (!this.radGridView1.ContainsFocus) |
{ |
this.radGridView1.EndEdit(); |
} |
} |
I didn’t understand the second issue. You can place your code just before EndEdit call.
Unfortunately, there is no global solution for this issue. We plan to address it in our upcoming release in November.
Mateo, please send us your project. We will try to locate the issue. I am looking forward to your reply.
Greetings,
Jack
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.