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 7921151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:28:48+00:00 2026-06-03T16:28:48+00:00

So i have this datagridview1 filled with a datatable(index 1) in a dataset(db1) and

  • 0

So i have this datagridview1 filled with a datatable(index 1) in a dataset(db1) and im trying to delete the currently selected row via Button.

private void delempl_Click(object sender, EventArgs e){
    db1.gettable(1).Rows[dataGridView1.CurrentRow.Index].Delete()
    db1.updatedb(); //sending the changes to my DB
}

I also write the first/lastname into 2 textboxes whenever the selection in the datagridview is changed by the user

private void dataGridView1_SelectionChanged(){
    lname.Text = db1.gettable(1).Rows[dataGridView1.CurrentRow.Index][2].ToString();
    fname.Text = db1.gettable(1).Rows[dataGridView1.CurrentRow.Index][1].ToString();
}

Deleting the last row works fine but when i try to delete one in the middle i get an DeletedRowInaccessible Exception on:

lname.Text = db1.gettable(1).Rows[dataGridView1.CurrentRow.Index][2].ToString();

I guess the moment the row gets deleted, the selection changes and triggers the dataGridView1_SelectionChanged-Event.

Any way to fix that?

  • 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-06-03T16:28:50+00:00Added an answer on June 3, 2026 at 4:28 pm

    A deleted row is still present in the datatable but you can’t read its properties.
    You should check if the CurrentRow is deleted or not

    private void dataGridView1_SelectionChanged()
    { 
        DataTable tb = db1.gettable(1);
        if(dataGridView1.CurrentRow != null && dataGridView1.CurrentRow.Index != -1 && 
           tb[dataGridView1.CurrentRow.Index].RowState != DataRowState.Deleted)
        {
            lname.Text = tb.Rows[dataGridView1.CurrentRow.Index][2].ToString(); 
            fname.Text = tb.Rows[dataGridView1.CurrentRow.Index][1].ToString(); 
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a DataGridView Control, this grid is filled through a DataTable. Now,
I have a List and a dataGridView1 and I'm trying to do this: var
I have a data grid on my form filled by a dataset. On the
I have this button with the code: private void button22_Click_1(object sender, EventArgs e) {
I have a column 'date' in my DataSet. I would like to filter this
I am very confused and have spent a long time trying to debug this
I have a datagridview in a C# Winform project. This datagridview is used to
Background I have a custom collection that is binded to the datagridview this.datagridview.DataSource =
I have a DataGridView populated with a BindingList . This list gets saved into
This is really driving me nuts, I have a datagridview bound to a bindingsource,

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.