We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Null reference exception when attempting to delete a record after a closing a dropdown combo in the recordvaluechanging event

I have a ggc that have a combo box in a row. When the user select a value in the combo box, I want to delete the row based on a certain logic that I am checking in the RecordValueChanging event.

However, I am getting an null reference exception in the TableControlCurrentCellCloseDropDown event, which I am also using like this...

private void gridGroupingControl1_TableControlCurrentCellCloseDropDown(object sender, GridTableControlPopupClosedEventArgs e)
{
if (e.Inner.PopupCloseType == Syncfusion.Windows.Forms.PopupCloseType.Done)
{
e.TableControl.CurrentCell.EndEdit();
e.TableControl.Table.EndEdit();
}
}

The issue is that the RecordValueChanging event fires before I the TableControlCurrentCellCloseDropDown event, so the called to e.TableControl.Table.EndEdit(); is raising the null reference error because I have already deleted that record.

1 Reply

JS Jeba S Syncfusion Team August 23, 2007 01:23 PM UTC

Hi James,

Thank you for your details.

You can avoid the NullReferenceException by lock and unlock the current cell. The Lock / Unlock blocks any changes to the active current cell.

Please refer this code snippets:

private void gridGroupingControl1_TableControlCurrentCellCloseDropDown(object sender, GridTableControlPopupClosedEventArgs e)
{
if (e.Inner.PopupCloseType == Syncfusion.Windows.Forms.PopupCloseType.Done && this.gridGroupingControl1.Table.CurrentRecord!=null)
{
GridCurrentCell cc = this.gridGroupingControl1.TableControl.CurrentCell;
cc.ConfirmChanges();
cc.Lock();
((GridTableControl)cc.Grid).Table.CurrentRecordManager.EndEdit();
e.TableControl.CurrentCell.EndEdit();
e.TableControl.Table.EndEdit();
cc.Unlock();
}
}


Kindly let us know if you need any further assistance.

Thank you for using Syncfusion Products.

Best Regards,
Jeba.

Loader.
Live Chat Icon For mobile
Up arrow icon