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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:56:12+00:00 2026-05-13T12:56:12+00:00

I’ve been using WinForms databinding to display data from a database mapped with Fluent

  • 0

I’ve been using WinForms databinding to display data from a database mapped with Fluent NHibernate, and that’s been working great.

For example, I can just set a DataGridView’s DataSource property from an entity’s IList property, and voila – there’s all the data!

But now I need to start adding and saving new data rows, and that’s not going so well. I thought I’d be able to just enable the grid’s AllowUserToAddRows property, and new rows would get added to the underlying IList in the entity, but that didn’t work.

Then, after a little searching, I tried setting the DataSource property to a BindingList that was populated from the IList, but that’s not being updated with new rows either.

During the course of my searches, I also came upon a few people reporting difficulty with WinForms and DataBinding in general, which makes me wonder if I should pursue that approach any further.

Is the DataBinding approach worth continuing? If so, can anyone suggest where I’m going wrong?

Or is it better to just handle all the DataGridView events associated with adding a new row, and writing my own code to add new objects to the IList property in my entity?

Other suggestions? (though I don’t think switching to WPF is going to be an option, no matter how much better the databinding may be)

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

    Can you load (or copy) your nHibernate entities into a generic List? If so, I have had good success in with two-way binding using a DataGridView bound to a generic List.

    The key points are:

    • The generic list contains list objects where each is an instance of your custom class.
    • Your custom class must implement public properties for each of the fields to bind. Public fields didn’t work for me.
    • Use a BindingSource to wrap the actual generic list.
    • The BindingSOurce allows you to set the AllowNew property to true. Binding directly to the List almost works, but the DataGridVieww does not display the “New row” line, even if AllowUsersToAddRows = true.

    For example, add this code to a Form with a dataGridView1:

        private List<MyObject> m_data = new List<MyObject>();
    
        private BindingSource m_bs =new BindingSource();
    
    
        private void Form1_Load(object sender, EventArgs e)
        {
    
            m_data.Add(new MyObject(0,"One",DateTime.Now));
            m_data.Add(new MyObject(1, "Two", DateTime.Now));
            m_data.Add(new MyObject(2, "Three", DateTime.Now));
    
            m_bs.DataSource = m_data;
            m_bs.AllowNew = true;
    
            dataGridView1.DataSource = m_bs;
            dataGridView1.AutoGenerateColumns = true;
            dataGridView1.AllowUserToAddRows = true;
    
        }
    
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            for (int i = 0; i < m_data.Count ; i++)
            {
                Console.WriteLine(string.Format("{0} {1}  {2}", m_data[i].ID, m_data[i].Name, m_data[i].DOB));                
            }
        }
    }
    
    public class MyObject
    {
        // Default ctor, required for adding new rows in DataGridView
        public MyObject()
        {
        }
    
        public MyObject(int id, string name, DateTime dob)
        {
            ID = id;
            Name = name;
            DOB = dob;
    
        }
    
        private int m_id;
        public int ID
        {
            get
            {
                return m_id;
            }
            set
            {
                m_id = value;
            }
        }
    
    
        private string m_name;
    
        public string Name
        {
            get
            {
                return m_name;
            }
            set
            {
                m_name = value;
            }
        }
    
        private DateTime m_dob;
    
        public DateTime DOB
        {
            get
            {
                return m_dob;
            }
            set
            {
                m_dob = value;
            }
        }
    }
    

    When the form closes, the contents of the bound List are printed to the Output window.

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

Sidebar

Ask A Question

Stats

  • Questions 441k
  • Answers 441k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'll need to output the PHP array in a way… May 15, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer For the authoritative list of snippets, check out the VS2010… May 15, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer Here is a guess. Assume the platform is 32 bit.… May 15, 2026 at 5:39 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.