// 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();
}
|
// Under form loading method
this.sfDataGrid.AllowDeleting = true;
this.sfDataGrid.AutoGenerateColumns = false;
sfDataGrid.DataSource = data.OrdersListDetails;
this.sfDataGrid.Columns.Add(new GridButtonColumn()
{
MappingName = "Quantity",
HeaderText = "Remove",
AllowDefaultButtonText = true,
DefaultButtonText = "Remove this row"
});
this.sfDataGrid.CellButtonClick += sfDataGrid_CellButtonClick;
|
// Under form loading method
this.sfDataGrid.AllowDeleting = true;
this.sfDataGrid.AutoGenerateColumns = true;
this.sfDataGrid.AutoGeneratingColumn += sfDataGrid_AutoGeneratingColumn;
sfDataGrid.DataSource = data.OrdersListDetails;
void sfDataGrid_AutoGeneratingColumn(object sender, Syncfusion.WinForms.DataGrid.Events.AutoGeneratingColumnArgs e)
{
if (e.Column.MappingName == "Quantity")
{
GridButtonColumn column = new GridButtonColumn()
{
MappingName = "Quantity",
HeaderText = "Remove",
AllowDefaultButtonText = true,
DefaultButtonText = "Remove this row"
};
e.Column = column;
}
} |