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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:47:23+00:00 2026-05-22T12:47:23+00:00

Has anyone managed to bind a DataNavigator and a DataGrid using the DataSource property

  • 0

Has anyone managed to bind a DataNavigator and a DataGrid using the DataSource property and the ADO.NET Entity Framework so that add and delete (+ and – buttons in the data navigator). work? I have the problem, that everytime i click on the add button of the DataNavigator, the EntityState is always set to detached. I can’t figure out, how to add this detached entity to the DataContext.

my code is simple (using a static session class and a partial class):

internal class Session
{
    private static Entities _entities;

    public static Entities Entities
    {
        get { return _entities ?? (_entities = new Entities()); }
        set { _entities = value; }
    }
}

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        InitData();
    }

    private void InitData()
    {
        gridControl1.DataSource = Session.Entities.SomeObjects;
        dataNavigator1.DataSource = Session.Entities.SomeObjects;
    }
}

public partial class SomeObjects
{
    public SomeObjects()
    {
        PropertyChanged += SomeObject_PropertyChanged;
        ObjectId = Guid.NewGuid();
    }

    private void SomeObject_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
            Debug.WriteLine(EntityState); // when i change a existing record in the grid, EntityState is set to modified and can be saved easily using SaveChanges. But when i add a new entity, EntityState is always set to detached.
    }
}

Help’s appreciated!

-christian

  • 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-22T12:47:24+00:00Added an answer on May 22, 2026 at 12:47 pm

    I think you should use BindingSource control instead of using DataSource and handle AddingNew event to manually set State to Added by calling AddObject.

    DataGrid doesn’t know anything about source of data so it cannot communicate with entity framework context / set and add object. You must do it manually and for that you need some event to handle when new record is added. I believe AddingNew and BindingSource is way to go.

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

Sidebar

Related Questions

Has anyone worked much with Microsoft's Managed Extensibility Framework (MEF)? Kinda sounds like it's
Has anyone managed to create a CTE in SQL Server's T-SQL that also includes
Has anyone managed to use ItemizedOverlays in Android Beta 0.9? I can't get it
Has anyone managed to get subsonic or a variant working on Windows Mobile? We
Has anyone managed to activate Gzip compression on a website in IIS6 ? We're
Has anyone tried installing SQL Server 2008 Developer on a machine that already has
Has anyone run into this error message before when using a timer on an
Has anyone built a website with IronPython and ASP.NET. What were your experiences and
Has anyone managed to get administration rights through the UAC without restarting the application
Has anyone managed to get a custom IMessageInterpolator working to enable customisation of error

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.