How get Id of Row selected in windows Form

Hi,
I using GridGroupingControl and I would to delete the row selected, I have architecture DAL BL PL so I have in Busineess Layer Delete(id).Now I want when I select the row in grid Grouping and click on DeleteButon this row must delete from grid and from my table Client.
private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
{
CLIENT clt = new CLIENT();
IClientBusiness ClientBusiness = new ClientBusiness();
Record r = this.gridGroupingControl1.Table.CurrentRecord;
if (r != null)
{
r.Delete();
this.gridGroupingControl1.Table.TableDirty = true;
r = this.gridGroupingControl1.Table.CurrentRecord;
this.gridGroupingControl1.Table.SelectedRecords.DeleteAll();
int id = gridGroupingControl1.TableModel.RowCount + 1;
ClientBusiness.Delete(id);
}
My problem is "id" I can't get it and I get exception Erreur "The value can not be null. \ R \ n Parameter name: entity "
Thank you.

1 Reply

AR Arulpriya Ramalingam Syncfusion Team October 12, 2017 12:01 PM UTC

Hi Hajer,   
   
Thanks for using Syncfusion products.   
   
By default, the changes will be reflected in the underlying data source of the grid whenever the records in the grid is modified or deleted. From your code part we suspect that you want to retrieve the index of selected records. In order to get the index of the record, the IndexOf() method of UnsortedRecordsCollection can be used. We have created a simple sample as per your requirement and please make use of the below code and sample,   
   
Code example:  
   
//Event customization   
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)   
{   
    //To delete the selected records   
    if(this.gridGroupingControl1.Table.SelectedRecords.Count > 0)   
    {   
        Record record = this.gridGroupingControl1.Table.SelectedRecords[0].Record;   
        //Index of the record in data source   
        int index = this.gridGroupingControl1.Table.UnsortedRecords.IndexOf(record);   
        MessageBox.Show(index.ToString());   
    }   
    this.gridGroupingControl1.Table.SelectedRecords.DeleteAll();   
}   
   
   
If still the issue exists, please provide stack trace of the exception.   
   
Regards,   
Arulpriya   


Loader.
Up arrow icon