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

The Archive Base Latest Questions

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

It’s a pleasure to see how much knowledge people have on here, it’s a

  • 0

It’s a pleasure to see how much knowledge people have on here, it’s a treasure of a place.
I’ve seen myself writing code for DataGridView events – and using DataSource to a backend prepared DataTable object.

Sometimes the user can remove rows, update them etc. and the underlying data will need validation checks again.

Let’s assume we have a person class

class Person {
    public string FirstName { get; set; }       
}

Let’s say some other part of the code deals with creating an array of Person.

class Processor {
       public static Person[] Create()
       {
           ....
           ....
           return person[];
       }
}

And this information would appear on a DataGridView for user viewing.
I’ve tried something like this:

public static DataTable ToTable(List<Person> list)
{   ...   }

And had this method in the Person class .. which I would think it’d belong to. Then I would bind the DataGridView to that DataTable and the user will then see that data and do their tasks.

But I’ve thought of using BindingList<> which I’m not so educated on yet.. would I still have the same capability of sorting the DataGridView like it does with DataTable as a DataSource? Would BindingList be implemented by a container class like “PersonCollection” or would the Person class implement itself? I would like to fire some events to be able to modify the collection in a clean way without having to reset datasources, etc. Where the user experience could really be affected.

I understand that modifying the DataSource DataTable is the good way. But sometimes I need to fire methods in the corresponding class that that specific row refers to, and had an ugly extra hidden column which would hold a reference to the existing object somewhere else (the Person reference).

If you guys know a better design solution, I would be more than happy to hear it.
Thanks in advance,

PS. After reading “The Pragmatic Programmer”, I just can’t stop thinking critically about code!

Leo B.

  • 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-12T07:09:07+00:00Added an answer on May 12, 2026 at 7:09 am

    Create a business object class. Implement INotifyPropertyChanged. Look at the code below:

    public class Employee:INotifyPropertyChanged
        {
            public Employee(string Name_, string Designation_, DateTime BirthDate_)
            {
                this.Name = Name_;
                this.Designation = Designation_;
                this.BirthDate = BirthDate_;
            }
    
    
            #region INotifyPropertyChanged Members
            public event PropertyChangedEventHandler PropertyChanged;
            #endregion
    
            private void NotifyPropertyChanged(String info)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(info));
                }
            }
    
            [DisplayName("Employee Name")]
            public string Name
            {
                get { return this._Name; }
    
                set
                {
                    if (value != this._Name)
                    {
                        this._Name = value;
                        NotifyPropertyChanged("Name");
                    }
                }
            }
            private string _Name = string.Empty;
    
            [DisplayName("Employee Designation")]
            public string Designation
            {
                get { return this._Designation; }
    
                set
                {
                    if (value != this._Designation)
                    {
                        this._Designation = value;
                        NotifyPropertyChanged("Designation");
                    }
                }
            }
            private string _Designation = string.Empty;
    
            public DateTime BirthDate
            {
                get { return this._BirthDate; }
    
                set
                {
                    if (value != this._BirthDate)
                    {
                        this._BirthDate = value;
                        NotifyPropertyChanged("BirthDate");
                    }
                }
            }
            private DateTime _BirthDate = DateTime.Today;
    
            [DisplayName("Age")]
            public int Age
            {
                get
                {
                    return DateTime.Today.Year - this.BirthDate.Year;
                }
            }
      }
    

    Create your custom collection:

    public class EmployeeCollection:BindingList<Employee>
        {
            public new void  Add(Employee emp)
            {
                base.Add(emp);
            }
    
            public void SaveToDB()
            {
               //code to save to db
            }
        }
    

    Set the data source:

     _employeeStore = new EmployeeCollection(); 
    this.dataGridView1.DataBindings.Add("DataSource", this, "EmployeeStore");
    

    Now if you want to add an employee to your datagridview,

    Employee employee = new Employee(textBoxName.Text, textBoxDesignation.Text, dateTimePicker1.Value);            
    _employeeStore.Add(employee);
    

    This is very clean. You just play with business object and don’t touch the UI.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.