Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6200111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:18:28+00:00 2026-05-24T04:18:28+00:00

I am trying to delete multiple selected rows from a DataGridView. When I try

  • 0

I am trying to delete multiple selected rows from a DataGridView. When I try the code below, it will only delete just a few of the selected rows. An example, I have seven rows, I select 5 consecutive rows and press delete and only three get deleted.

    IEnumerable<DataGridViewRow> dgvrs = from dgvrws in dgvChemicalInv.Rows.Cast<DataGridViewRow>()
                                                 where dgvrws.Selected.Equals(true)
                                                 select dgvrws;

            foreach ( DataGridViewRow dgr in dgvrs )
            {
                dctchemri = dgr.Cells["DCT_CHEMRI"].Value.ToString();
                index = dgvChemicalInv.CurrentRow.Index;

                var chemObj = ( from chmObj in DCTProjectNodeObj.Chemicals
                                where chmObj.DCTChemRI.Equals(dctchemri)
                                select chmObj ).Single();

                if ( sqlCmd.Delete_Chems(this.projID, (csDCTChemicalObj)chemObj) )
                {
                    dgvChemicalInv.Rows.Remove(dgr);
                }
                if ( dgvChemicalInv.RowCount > 0 )
                {
                    DCTProjectNodeObj.Chemicals.Remove((csDCTChemicalObj)chemObj);
                }
                else
                {
                    DCTProjectNodeObj.Chemicals = new List<csDCTChemicalObj>();
                    DO_BtnSaveClickEvent();
                }
            }

Thank you,

Bill O.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:18:29+00:00Added an answer on May 24, 2026 at 4:18 am

    Your code is a little difficult to read, but I think that you are making this too complicated. I would recommend using something like a BindingSource object. It makes table management much easier. Set the datasource of the BindingSource to the table and the datasource of the DataGridView to the BindingSource object, and any changes made to the table will be reflected in the DataContext after calling SubmitChanges().

    Example:

    MyDataContext dataContext = new MyDataContext();
    BindingSource bindingSource = new BindingSource();
    
    bindingSource.DataSource = dataContext.MyTable;
    dataContext.DataSource = bindingSource;
    

    It’s been a while since I’ve done this, but I think this is the easiest way to do it. This avoids any messy operations, however it can lead to complications with foreign key relationships.

    Just a way that might make things simpler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I'm trying to delete multiple rows from a table and one of those
I'm trying to use SQL to delete multiple rows from multiple tables that are
I am trying to delete multiple rows from a GridView but I am struggling
I am trying to delete several rows from a MySQL 5.0.45 database: delete from
I'm trying to delete all digits from a string. However the next code deletes
im trying to do delete records from multiple database tables. For error handling i'm
I am trying to delete from multiple tables. Here's what my tables look like
Hi Guys I'm trying to delete multiple events from the Google Calendar API (From
While searching for clues on how i can delete multiple rows from QTableView i
I'm trying to delete a directory that contains XML files from a remote computer.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.