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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Delete button or something else?

Thread ID:

Created:

Updated:

Platform:

Replies:

144735 May 20,2019 12:44 PM UTC May 23,2019 01:07 PM UTC WinForms 6
loading
Tags: SfDataGrid
Arthur
Asked On May 20, 2019 12:52 PM UTC

Hello, is it possible to delete a row besides the delete key? like binding to a button, confirmation pop-up message on delete key or anything else?



Jagadeesan Pichaimuthu [Syncfusion]
Replied On May 20, 2019 03:14 PM UTC

Hi Arthur, 
 
Thanks for using Syncfusion product. 
 
The selected records can be deleted when clicking the cell button by using the DeleteSelectedRecords method in the SfDataGrid.CellButtonClick event. Please refer the below documentation link for your reference, 
 
Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan 


Arthur
Replied On May 20, 2019 04:25 PM UTC

I got a System.NullReferenceException: 'object reference not set to an instance of an object.'


I'm using DataSource for my grid table does it affect something?

Arthur
Replied On May 20, 2019 04:40 PM UTC

Ok, i'm not getting an exception anymore, don't know if i did it right: Should I use "this.sfDataGrid1.CellButtonClick += Double2Click;" on the Load method or under "InitializeComponent()" ?

but now when I click it, it doesn't do anything
 

Jagadeesan Pichaimuthu [Syncfusion]
Replied On May 21, 2019 09:17 AM UTC

Hi Arthur, 
Thanks for your update. 
 
We have checked the provided link, but it “Page Not Found” error occurs while open the provided link. And we have tried to reproduce the reported problem in our end with button click operation, but it works properly in our end. Please find the below code snippet, 
// 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();  
}  
 
 
Please find the sample from below location. 
 
Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan

Arthur
Replied On May 22, 2019 12:01 PM UTC


Jagadeesan Pichaimuthu [Syncfusion]
Replied On May 23, 2019 01:07 PM UTC

Hi Artur, 
 
Thanks for your update. 
 
We have checked the provided sample code in our end, but we could not find any code related to creating the button column. The CellButtonClick event will be fired only when click on the button cell(any cell in button column). You can able to add the button column to SfDataGrid in two ways. 
 
First way : If AutoGenerateColumns is false: 
 
When AutoGeneratedColumns is false, you need to create and add the columns by yourself. Please refer the below code snippet for adding the Button column in SfDataGrid. 
 
// 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; 
 
 
 
Second way: If AutoGenerateColumns is true: 
 
When AutoGenerateColumns is true, you can able to initialize the button column using the AutoGeneratingColumn for particular column. Please find the code snippet to add the button column below, 
 
// 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; 
    } 
} 
 
Once you added the button column you can wire the CellButtonClick event. Also ensure the AllowEditing is true for SfDataGrid control. We have prepared the simple sample and video for your reference. 
 
 
Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon