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

Sfdatagrid loop deletes the items selected by the checkbox?

Thread ID:

Created:

Updated:

Platform:

Replies:

144133 Apr 21,2019 10:33 AM UTC Apr 22,2019 09:39 AM UTC WinForms 3
loading
Tags: SfDataGrid
JM
Asked On April 21, 2019 10:33 AM UTC

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();
                    }
                }
            }
        }




Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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
Replied On April 22, 2019 09:23 AM UTC

OK!!!!good!
Code is very cool 

Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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 


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