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

event when button of GridButtonColumn is clicked

I added a GridButtonColumn to my SfdatagridView so that each row has a button (I want to use it for deleting this row). How is it possible to react on pushing the button of a specific row?

1 Reply

JP Jagadeesan Pichaimuthu Syncfusion Team May 16, 2019 05:44 AM

Hi Hans-Georg, 

Thanks for using Syncfusion product. 

We have checked your requirement to delete the row while button click on the particular row. You can able to achieve your requirement by using the CellButtonClick event. Please refer the below code snippet to delete the record by two different ways. 

// Add the below code in constructor or form loading 
 
this.sfDataGrid.AllowDeleting = true; 
 
this.sfDataGrid.Columns.Add(new GridButtonColumn() 
{ 
    MappingName = "Quantity", 
    HeaderText = "Remove", 
    AllowDefaultButtonText = true, 
    DefaultButtonText = "Remove this row" 
}); 
 
this.sfDataGrid.CellButtonClick += sfDataGrid_CellButtonClick; 
 
 
void sfDataGrid_CellButtonClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellButtonClickEventArgs e) 
{ 
    int _Dgdeletingrowindex = sfDataGrid.TableControl.ResolveToRecordIndex(sfDataGrid.CurrentCell.RowIndex); 
 
    // Delete record by based on the row index 
    sfDataGrid.View.RemoveAt(_Dgdeletingrowindex); 
 
   // Or you can call the below code the delete the selected record 
   // this.sfDataGrid.DeleteSelectedRecords(); 
} 
 

We have prepared the simple sample to achieve your requirement. 

Let us know whether this helps also if you need any further assistance on this. 

Regards, 
Jagadeesan 


Loader.
Live Chat Icon For mobile
Up arrow icon