How to resolve null reference exception in WinForms GridGroupingControl?
Resolve null reference exception
While changing the DataSource in the ComboBox cell in WinForms GridGroupingControl, a null reference exception is raised. This is because the database is updated and then refreshed after you pick a value from a ComboBox cell by using the RecordValueChanged event. The newly edited value is not committed while the database updates. So, when you try to click on the next row, the RecordValueChanged event refreshes the database before the ComboBox commits the new value into the underlying database.

Figure 1: Null reference exception
This can be solved by calling the EndEdit in the TableControlCurrentCellCloseDropDown event. Refer to the following code example.
C#
void gridGroupingControl1_TableControlCurrentCellCloseDropDown(object sender, GridTableControlPopupClosedEventArgs e)
{
if(e.Inner.PopupCloseType == Syncfusion.Windows.Forms.PopupCloseType.Done)
{
// Commits value in the ComboBox manually.
e.TableControl.CurrentCell.EndEdit();
}
}VB
Private Sub gridGroupingControl1_TableControlCurrentCellCloseDropDown(ByVal sender As Object, ByVal e As GridTableControlPopupClosedEventArgs)
If e.Inner.PopupCloseType = Syncfusion.Windows.Forms.PopupCloseType.Done Then
'Commits value in the ComboBox manually.
e.TableControl.CurrentCell.EndEdit()
End If
End Sub
Conclusion
I hope you
enjoyed learning how to resolve null reference exceptions in
GridGroupingControl.
You can refer to WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations and WinForms GridGroupingControl documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms GridGroupingControl example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!