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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:12:09+00:00 2026-05-14T03:12:09+00:00

I have two classes: Employee and EmployeeGridViewAdapter . Employee is composed of several complex

  • 0

I have two classes: Employee and EmployeeGridViewAdapter. Employee is composed of several complex types. EmployeeGridViewAdapter wraps a single Employee and exposes its members as a flattened set of system types so a DataGridView can handle displaying, editing, etc.

I’m using VS’s builtin support for turning a POCO into a data source, which I then attach to a BindingSource object. When I attach the DataGridView to the BindingSource it creates the expected columns and at runtime I can perform the expected CRUD operations. All is good so far.

The problem is the collection of adapters and the collection of employees aren’t being synchronized. So all the employees I create an runtime never get persisted. Here’s a snippet of the code that generates the collection of EmployeeGridViewAdapter‘s:

        var employeeCollection = new List<EmployeeGridViewAdapter>();
        foreach (var employee in this.employees)
        {
            employeeCollection.Add(new EmployeeGridViewAdapter(employee));
        }
        this.view.Employees = employeeCollection;

Pretty straight forward but I can’t figure out how to synchronize changes back to the original collection. I imagine edits are already handled because both collections reference the same objects but creating new employees and deleting employees aren’t happening so I can’t be sure.

  • 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-14T03:12:10+00:00Added an answer on May 14, 2026 at 3:12 am

    The first problem seems to be that you are creating a new list and data binding to that. When you’re adding elements these will be added to the collection but your original employee list remains unmodified.

    To avoid this you should either provide a custom collection class that will migrate changes back to the underlying employee list, or wire up the appropriate events (to do the migration on insert/delete) before data binding to it.

    To avoid a number of other problems with binding editable collections to grids, you should implement the data binding interfaces, as outlined below. The presence of these interfaces allows the visual controls to notify the underlying collection about actions such as “insert cancelled” (when users aborts entry of a new record), and similarly allows information to flow in the opposite direction (update UI when collection or individual entries change).

    First, you’ll want to implement at least IEditableObject, INotifyPropertyChanged and IDataErrorInfo on the individual items in a data-bound collection, which in your case would be the EmployeeGridViewAdaper class.

    Additionally, you’d want your collection to implement ITypedList and INotifyCollectionChanged. The BCL contains a BindingList implementation which provides a good starting point for this. Recommend using this instead of the plain List.

    I can recommend Data Binding with Windows Forms 2.0 for an exhaustive coverage of this topic.

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

Sidebar

Related Questions

I have two classes Address and Employee as follows: public class Address { public
I have 3 classes, two inherit from 1: public class Employee { private virtual
I have two Classes (i.e. Customer , and Employee ) and a generic repository
I have two Model classes: Attendance and Employee. I have defined the Employee class
I have two classes class Deptartment{ int deptid, String deptname; List<Employee> employees; } class
I have two classes. One is called Employee and the other EmployeeDetails that has
I have two objects of classes Person and Employee. Both classes have common attribute
In a c#.net application I have a two classes as below Employee EmployeeId :
I have two classes in Grails application , Employee has hasMany(one To Many relations)
Lets say you have two classes, Boss and Employee. There is a bidirectional many-to-many

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.