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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:04:46+00:00 2026-06-09T22:04:46+00:00

New to entity framework, but I would think this should be pretty simple. My

  • 0

New to entity framework, but I would think this should be pretty simple.

My form load creates a context from my Entities. I create a list of clients and have a binding source that I assign clients to. The binding source is assigned to a Binding Navigator – clientBindingNavigator.

private void ClientExtForm_Load (object sender, EventArgs e)
        {

        _context = new IDVisitorEntities ();

        List<IDVM.Client> clients = _context.Clients.ToList ();

        clientBindingSource.DataSource = clients;

        }

excerpt from ClientExtForm.Designer.cs

        //
        // clientBindingNavigator
        // 
        this.clientBindingNavigator.AddNewItem = this.bindingNavigatorAddNewItem;
        this.clientBindingNavigator.BindingSource = this.clientBindingSource;
        this.clientBindingNavigator.CountItem = this.bindingNavigatorCountItem;
        this.clientBindingNavigator.DeleteItem = this.bindingNavigatorDeleteItem;
        this.clientBindingNavigator.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.bindingNavigatorMoveFirstItem,
        this.bindingNavigatorMovePreviousItem,
        this.bindingNavigatorSeparator,
        this.bindingNavigatorPositionItem,
        this.bindingNavigatorCountItem,
        this.bindingNavigatorSeparator1,
        this.bindingNavigatorMoveNextItem,
        this.bindingNavigatorMoveLastItem,
        this.bindingNavigatorSeparator2,
        this.bindingNavigatorAddNewItem,
        this.bindingNavigatorDeleteItem,
        this.clientBindingNavigatorSaveItem});

When I click the Delete Button on the navigator tool bar the the ClientBindingSource.Count has been reduced by 1 .

private void clientBindingNavigatorSaveItem_Click (object sender, EventArgs e)
        {
        this.OnSave ();
        }



public override void OnSave ()
        {

        foreach (ObjectStateEntry entry in _context.ObjectStateManager.GetObjectStateEntries (EntityState.Deleted))
            {
           // nothing shows up in this
            }            
        foreach (ObjectStateEntry entry in _context.ObjectStateManager.GetObjectStateEntries (EntityState.Modified))
            {
            // when modified 
            }

        foreach (ObjectStateEntry entry in _context.ObjectStateManager.GetObjectStateEntries (EntityState.Added))
            {
            // when adding this finds it                    
            }

        clientBindingSource.EndEdit ();

        visitorHostsBindingSource.EndEdit ();

        _context.SaveChanges ();

        base.OnSave (); 
        }

It appears as though the navigator is removing the item from the collection.

Added info: It appears that in the navigator the DeleteItem button corresponds to the RemoveCurrent method (on click event calls it). Not sure how to tie in before the RemoveCurrent does it’s thing.

What are my options for preforming the delete?

  • 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-09T22:04:48+00:00Added an answer on June 9, 2026 at 10:04 pm

    After looking around found some blogs that suggest to not use the default DeleteItem.

    this.clientBindingNavigator.DeleteItem = null;//= this.bindingNavigatorDeleteItem;

    In my case to make it clear for the BindingNavigator I replaced this.bindingNavigatorDeleteItem with a new button this.toolStripButton1 in the Items list.

    this.clientBindingNavigator.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.bindingNavigatorMoveFirstItem,
            this.bindingNavigatorMovePreviousItem,
            this.bindingNavigatorSeparator,
            this.bindingNavigatorPositionItem,
            this.bindingNavigatorCountItem,
            this.bindingNavigatorSeparator1,
            this.bindingNavigatorMoveNextItem,
            this.bindingNavigatorMoveLastItem,
            this.bindingNavigatorSeparator2,
            this.bindingNavigatorAddNewItem,
            this.toolStripButton1,
            this.clientBindingNavigatorSaveItem});
    

    Creation of the new button looks like this:

            // 
            // toolStripButton1
            // 
            this.toolStripButton1.Image = ((System.Drawing.Image) (resources.GetObject ("bindingNavigatorDeleteItem.Image")));
            this.toolStripButton1.RightToLeftAutoMirrorImage = true;
            this.toolStripButton1.Name = "toolStripDeleteItem";
            this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
            this.toolStripButton1.Text = "Delete";
            this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
    

    The Click event then calls the RemoveCurrent (just like the default does) but I can get the current entity and stash it in an arrraylist for use on save.

    private void toolStripButton1_Click (object sender, EventArgs e)
            {
            var currentclient = (Client) clientBindingSource.Current;
            clientstodelete.Add (currentclient);
            clientBindingSource.RemoveCurrent ();
            }
    

    I didn’t need to create a new button, I just needed to have the this.clientBindingNavigator.DeleteItem not tied to a button. Because the DeleteItem creates a click event under the hood that calls the BindingSource.RemoveCurrent(). I might change the button back to the default one created but for illustration wanted everyone to see what was happening.

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

Sidebar

Related Questions

I am writing a new application using the Entity Framework. Where would the EF
I'm fairly new to entity framework and patterns. How would I insert data into
I am trying to do something with Entity Framework that I think is pretty
Normally the code for using the dbContext from Entity Framework looks something like this:
I heard about the new entity framework for .net, and decided to modify my
When adding a new Entity Framework object to a database, how could one have
I just downloaded and installed the brand new Entity Framework 5.0 beta 2 which
I am new to Entity Framework. I am currently doing a project in ASP.NET,
I'm new to Entity Framework and am using Database First. I have inherited a
I am very new to Entity Framework, so apologies if its a very bad

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.