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

  • Home
  • SEARCH
  • 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 1034561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:24:42+00:00 2026-05-16T14:24:42+00:00

Update: I checked the answer before I fully tested it still does not work.

  • 0

Update: I checked the answer before I fully tested it still does not work. I updated the code below so you should just be able to paste in to a empty WinForms project and it should compile.

UPDATE:
I have found that if I change the selected item on the ComboBox to any other item, it now behaves as expected (in my code below I would switch from test1 to test2). As I have not received any answers yet, I change the question to this.

Why do I have to change to a different item in the combo box before it will show the changes I make to the underlying data-source?

Here is a quick test case of what is happening.

  1. Change test1 to test1asdf text in txtBroken
  2. click off to commit change
  3. text in combo box does not update.
  4. Change combo box to test2
  5. change test2 to test2asdf text in txtBroken
  6. click off to commit change
  7. text in combo box immediately shows ‘test2asdf’ still displays test1 for first item in the drop-down
  8. change to test1
  9. combo box displays test1 text box displays test1asdf
  10. update text box to test1asd
  11. combo box immediately displays test1asd

Other than behind the scenes changing the selected item on load and changing it back (this seems like such a hack) how can I fix this?


I have a combo box databound to a BindingSource bound to a List<Holder> it has Holder.Name as its display value. I also have a text box bound to Holder.Name but if I change the text in the text box it will not change what is displayed in the combo box. Changing selected items and changing back will show the updated text in the text box, but will still have the old value displayed in the combo box. How do I make the item in the combo box update?

using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace Sandbox_Form
{
    public class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            lstBroken = new BindingList<Holder>();
            lstBroken.Add(new Holder("test1"));
            lstBroken.Add(new Holder("test2"));
            bsBroken = new BindingSource(lstBroken, null);
            cmbBroken.DataSource = bsBroken;
            cmbBroken.DisplayMember = "Name";
            cmbBroken.SelectedIndex = 0;
            txtBroken.DataBindings.Add("Text", bsBroken, "Name");
            txtBroken.TextChanged += new EventHandler(txtBroken_TextChanged);

        }

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        void txtBroken_TextChanged(object sender, EventArgs e)
        {
            ((Control)sender).FindForm().Validate();
        }
        private BindingSource bsBroken;
        private BindingList<Holder> lstBroken;
        private ComboBox cmbBroken;
        private TextBox txtBroken;
        private Label label1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.cmbBroken = new System.Windows.Forms.ComboBox();
            this.txtBroken = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // cmbBroken
            // 
            this.cmbBroken.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbBroken.FormattingEnabled = true;
            this.cmbBroken.Location = new System.Drawing.Point(12, 32);
            this.cmbBroken.Name = "cmbBroken";
            this.cmbBroken.Size = new System.Drawing.Size(94, 21);
            this.cmbBroken.TabIndex = 0;
            // 
            // txtBroken
            // 
            this.txtBroken.Location = new System.Drawing.Point(13, 60);
            this.txtBroken.Name = "txtBroken";
            this.txtBroken.Size = new System.Drawing.Size(93, 20);
            this.txtBroken.TabIndex = 1;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(13, 13);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(41, 13);
            this.label1.TabIndex = 2;
            this.label1.Text = "Broken";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtBroken);
            this.Controls.Add(this.cmbBroken);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private void cmbWorks_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
    public class Holder
    {
        public Holder(string name)
        {
            Name = name;
        }
        private string _Name;
        public string Name
        {
            get { return _Name; }
            set
            {
                _Name = value;
            }
        }
    }
}

If I bind to a List<String> instead using Holder.Name it works as expected (this is just a simple mock-up, the real class has more than just a name so a list of strings will not work). I think this is a clue to what is wrong but I don’t know what it is. Using an Observable instead of a list makes no difference.

  • 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-16T14:24:43+00:00Added an answer on May 16, 2026 at 2:24 pm

    Use a BindingList instead of a List. It was designed to address such issues. Dinesh Chandnani, a member of the .NET Client Team, states the following in a blog post:

    BindingList<T> is the new generic
    implementation of IBindingList which
    fires ListChanged event when items are
    added/removed/inserted/etc. from the
    list. bindingSource hooks on to these
    events and is thus “aware” of these
    changes and can notify controls bound
    thos this BindingSource.

    I was able to reproduce the issue you described in your updated entry, but didn’t quite reproduce the original issue without tweaking the code slightly.

    By using a BindingList<Holder> I was able to get an immediate response when focus left the textbox. It’s possible to get instant updates by using an overloaded method when adding a new data binding. I also set the BindingSource‘s DataSource directly since using a null dataMember in the overloaded constructor was not yielding the expected behavior.

    Here’s the code I ended up with based off your sample code:

    public partial class Form1 : Form
    {
        private BindingSource bs;
        private BindingList<Holder> bList;
    
        public Form1()
        {
            InitializeComponent();
    
            bList = new BindingList<Holder>();
            bList.Add(new Holder("test1"));
            bList.Add(new Holder("test2"));
    
            bs = new BindingSource();
            bs.DataSource = bList;
    
            cmb.DataSource = bs;
            cmb.DisplayMember = "Name";
            cmb.ValueMember = "Name";
    
            // updates when focus leaves the textbox
            txt.DataBindings.Add("Text", bs, "Name");
    
            // updates when the property changes
            //txt.DataBindings.Add("Text", bs, "Name", false, DataSourceUpdateMode.OnPropertyChanged);
        }
    }
    

    Comment out the first txt binding and uncomment the one below it to see the DataSourceUpdateMode.OnPropertyChanged in action.

    Here are some BindingList resources:

    • BindingSource and BindingList Of T – DataBinding made simple!
    • BindingSource – A Closer Look…
    • Databinding – Bindinglist, BindingSource and BusinessObjects – Part 1
    • Databinding – BindingList, BindingSource, and BusinessObjects: Part 2
    • Behind the Scenes: Improvements to Windows Forms Data Binding in the .NET Framework 2.0, Part 2

      EDIT: in reply to the issues you’re facing with your updated code, please make these changes:

    1) Replace bsBroken = new BindingSource(lstBroken, null); with:

    bsBroken = new BindingSource();
    bsBroken.DataSource = lstBroken;
    

    Or in one line: bsBroken = new BindingSource() { DataSource = lstBroken };

    This yields the expected behavior with an immediate response to changes (I also mentioned this before above). Do not use the overload that accepts a dataMember and set it to null. Doing so gives the buggy behavior you’re experiencing.

    2) After doing the above, I see no need for the txtBroken_TextChanged event. Comment out the event handler assignment to test, but you should be able to remove it completely.

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

Sidebar

Related Questions

(Note: updated with adopted answer below.) For a PostgreSQL 8.1 (or later) partitioned table,
READ UPDATE 2 BELOW FOR THE ANSWER I'm trying to use ActionBarSherlock in my
The code has been updated to reference the changes below. This log system create
I need this query - update last but one record. UPDATE changes SET checked=''
I found this answer before, to fire an alert if the button is pressed
Just updated jQuery UI from 1.8.5 to 1.8.16, and the modal dialogs I've been
Just a quick question I haven't found an answer for by searching... How do
I need to update a datastore entity in a way that will not be
Ok, I asked this question and got excellent code example as answer. The code
Just looking for a super simple answer here. My app returns this : 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.