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

delete a row in the record

private void butDelete_Click(object sender,EventArgs e)
{
if (grdDisplayItems.Table.CurrentRecord != null)
{
if (grdDisplayItems.Table.Records.Count == 1)
{
grdDisplayItems.Table.Records[0].Delete();
}
else
{
this.grdDisplayItems.Table.CurrentRecord.Delete();
}
//this.grdDisplayItems.Table.Records[0].Delete();
}
}
The delete method deletes all records except for the record that iis left out.for e if we have 4 records it deletes 3 records succesfully but the last record is not deleted at all


if the grid has just one record then also the record is not getting deleted
I am getting an exception object refrence not set to an instanc eof an object

Stack trace:
StackTrace " at System.Data.DataView.GetRow(Int32 index)\r at System.Data.DataView.System.Collections.IList.RemoveAt(Int32 index)\r at Syncfusion.Grouping.Table.DeleteRecord(Record r)\r at Syncfusion.Grouping.Record.Delete()" string






5 Replies

CI Christopher Issac Sunder K Syncfusion Team October 9, 2010 04:37 PM UTC

Hi Harshini,

Thank you for your interest in Syncfusion products.

To delete the records one – by – one, you can check whether the record count is greater than zero. Here is the code snippets which explains the deletion in GridGroupingControl.


private void button1_Click(object sender, EventArgs e)
{
if (this.gridGroupingControl1.Table.CurrentRecord != null)
{
this.gridGroupingControl1.Table.CurrentRecord.Delete();
}
else
{
if (this.gridGroupingControl1.Table.Records.Count > 0) // check with this condition
this.gridGroupingControl1.Table.Records[0].Delete();
}
}


Please refer the following sample which illustrates the above.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GGC_Deletion-1675744949.zip

Please let me know if you have any other concerns.

Regards,
Christo.




HA harshini October 13, 2010 02:46 PM UTC

hi..

the problem here is when zeroth record is reached the table still has the value i.e

grdDisplayItems.Table.CurrentRecord != null condition is satisfied and
this.grdDisplayItems.Table.CurrentRecord.Delete(); is executed because of which whole application terminates and i get the exception.



RC Rajadurai C Syncfusion Team October 14, 2010 08:09 PM UTC

Hi Harshini,

Thanks for your update.

The CurrentRecord will not be null when the focus is in the AddNewRecord row. Hence, you could handle the following modified condition instead.

if (this.gridGroupingControl1.Table.CurrentRecord != null && this.gridGroupingControl1.Table.CurrentRecord != this.gridGroupingControl1.Table.AddNewRecord)
{
this.gridGroupingControl1.Table.CurrentRecord.Delete();
}


Please let us know if you have any further concerns.

Regards,
Rajadurai



JU juan replied to harshini March 29, 2018 10:37 PM UTC

hi..

the problem here is when zeroth record is reached the table still has the value i.e

grdDisplayItems.Table.CurrentRecord != null condition is satisfied and
this.grdDisplayItems.Table.CurrentRecord.Delete(); is executed because of which whole application terminates and i get the exception.


hola soy un nuevo usuario


MG Mohanraj Gunasekaran Syncfusion Team March 30, 2018 04:33 AM UTC

Hi juan, 
 
Thanks for using Syncfusion product. 
 
In order to delete the current record, you can also use the Records.Count property. Please refer to the below code example, 
 
Code example 
if (this.gridGroupingControl1.Table.CurrentRecord != null && this.gridGroupingControl1.Table.Records.Count > 0) 
{
    this.gridGroupingControl1.Table.CurrentRecord.Delete();
}
 
 
 
 
We have documented GridGroupingControl guide lines and it will be available in following UG link, 
 
 
And also, we have provided more customization for GridGroupingControl. Please refer the below KB link, 
 
Please let us know if you have any other queries while using the GridGroupingControl. 
 
Regards, 
Mohanraj G 


Loader.
Live Chat Icon For mobile
Up arrow icon