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

Sfdatagrid loop deletes the items selected by the checkbox?

I want to pass the "select" Row, and if the checkstate is check, delete it.
Thank you!

CODE:
 private void Button1_Click(object sender, EventArgs e)
        {
            var records = sfDataGrid1.View.Records;
            foreach (var record in records)
            {
                var dataRowView = record.Data as DataRowView;
                if (dataRowView != null)
                {
                    var selected = dataRowView.Row["select"];
                    if (selected.GetType() != typeof(DBNull) && (bool)selected)
                    {
                        sfDataGrid1.DeleteSelectedRecords();
                    }
                }
            }
        }




3 Replies

JP Jagadeesan Pichaimuthu Syncfusion Team April 22, 2019 09:08 AM UTC

Hi Jiamingliang, 

Thanks for using Syncfusion product. 

Your requirement can be achieved by enable the AllowDeleting property to true and then add the records in SelectedItems property before calling the DeleteSelectRecords method. Please find the code snippet below to achieve your requirement, 

// Add in constructor 
this.sfDataGrid1.AllowDeleting = true; 
 
private void button1_Click(object sender, EventArgs e) 
{ 
    var records = sfDataGrid1.View.Records; 
    sfDataGrid1.SelectedItems.Clear(); 
    foreach (var record in records) 
    { 
        var dataRowView = record.Data as DataRowView; 
        if (dataRowView != null) 
        { 
            var selected = dataRowView.Row["select"]; 
            if (selected.GetType() != typeof(DBNull) && (bool)selected) 
            { 
                sfDataGrid1.SelectedItems.Add(record.Data); 
            } 
        } 
    } 
 
    sfDataGrid1.DeleteSelectedRecords(); 
} 

Please find the sample from below link, 


Before deleting records please find the screen shot below, 
 

And please find the below screen shot which after delete the records, 
 

If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further. 

Regards, 
Jagadeesan


JM JM April 22, 2019 09:23 AM UTC

OK!!!!good!
Code is very cool 


JP Jagadeesan Pichaimuthu Syncfusion Team April 22, 2019 09:39 AM UTC

Hi Jiamingliang, 

Thanks for your update. 

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 

Regards, 
Jagadeesan 


Loader.
Live Chat Icon For mobile
Up arrow icon