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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:25:49+00:00 2026-05-25T00:25:49+00:00

I want to delete a row from gridview and database – I write some

  • 0

I want to delete a row from gridview and database – I write some code but this code just delete the first row of my gridview!
Please help me. I used Entity Framework and wpf C#.

using (AccountingEntities cntx = new AccountingEntities())
{
   Producer item = this.grdProducers.SelectedItem as Producer;
   cntx.DeleteObject(cntx.Producers.First(x => x.ID == item.ID));
   cntx.SaveChanges();
   dataPager.Source = cntx.Producers.ToList();
}
  • 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-25T00:25:50+00:00Added an answer on May 25, 2026 at 12:25 am

    I find the solution: when i open the dialog for confirming the delete action, selected item changed. i should select the entityId before opening the dialog. the below code show how to do this:

                int unitTypeId = (this.grdUnitTypes.SelectedItem as UnitType).ID;
                ConfirmWindowResult result = Helpers.ShowConfirm(this, SR.GlobalMessages.AreYouSureToDelete, SR.GlobalMessages.Warning);
                if (result == ConfirmWindowResult.Yes)
                {
                    using (AccountingEntities cntx = new AccountingEntities())
                    {
                        try
                        {
                            cntx.UnitTypes.DeleteObject(cntx.UnitTypes.First(x => x.ID == unitTypeId));
                            cntx.SaveChanges();
                            dataPager.Source = cntx.UnitTypes.ToList();
                            MessageBox.Show("Success");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error");
                        }
                        finally
                        {
                            cntx.Dispose();
                        }
                    }
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to perform cascade delete for some tables in my database, but I'm
Hm, First time i see this when i want to delete row: ( I
I want to Delete a row in the Gridview which is in the update
I want to delete foo() if foo() isn't called from anywhere.
I want to delete all but the 4 newest directories in my parent directory.
I'm writing an application in PHP 5. I want to delete some rows in
I just got this message from Visual Studio 2005, when I clicked on the
I want to delete every row where the time difference is 5 minutes. I'm
I want to capture the user's name who deletes a row, when delete action
Hey guys i wrote a quick test. I want delete to call deleteMe which

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.