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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:08:32+00:00 2026-05-13T07:08:32+00:00

I have created a C# Windows Forms application which I’ve attempted to make as

  • 0

I have created a C# Windows Forms application which I’ve attempted to make as simple as possible to demonstrate a problem I am running into. I’m trying to use a DataGridView to allow user input in one column while simultaneously getting updates in another column from a background thread.

The problem is that the Input column is effectively un-editable because — I think — the updates which are intended for the Output column cause the Input column to be updated with it’s current value while the user is attempting to change it.

Is this a bug in DataGridView? Is there a better way to do this sort of thing? Can anyone recommend a good workaround?

The following code demonstrates the problem. The Output column will continuously update and the Input column is virtually uneditable. I’ve merged the designer code (Form1.designer.cs), and Main (from Program.cs) into the form code (Form1.cs) — so the following code should work on its own.

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

public partial class Form1 : Form
{
    private System.ComponentModel.IContainer components = null;

    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.dataGridView = new System.Windows.Forms.DataGridView();
        ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
        this.SuspendLayout();
        // 
        // dataGridView
        // 
        this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        this.dataGridView.Location = new System.Drawing.Point(3, 12);
        this.dataGridView.Name = "dataGridView";
        this.dataGridView.RowTemplate.Height = 24;
        this.dataGridView.Size = new System.Drawing.Size(322, 158);
        this.dataGridView.TabIndex = 0;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(328, 174);
        this.Controls.Add(this.dataGridView);
        this.Name = "Form1";
        this.Text = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);
        ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.DataGridView dataGridView;

    public Form1()
    {
        InitializeComponent();
    }

    BindingSource bindingSource = new BindingSource();
    BindingList<Item> items = new BindingList<Item>();
    private System.Timers.Timer timer;
    private void Form1_Load(object sender, EventArgs e)
    {
        dataGridView.DataSource = bindingSource;
        bindingSource.DataSource = items;
        items.Add(new Item(dataGridView));

        timer = new System.Timers.Timer {Interval = 50};
        timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
        timer.Start();
    }

    private Random random = new Random();
    void timer_Elapsed(object sender, ElapsedEventArgs e)
    {
        items[0].SetOutput(random.Next(100));
    }
}


class Item : INotifyPropertyChanged
{
    public int Input { get; set; }

    private int output;
    public int Output
    {
        get { return output; }
        private set
        {
            output = value;
            OnPropertyChanged("Output");
        }
    }

    public Control control;

    public Item(Control control)
    {
        this.control = control;
    }

    public void SetOutput(int outputValue)
    {
        Output = outputValue;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void OnPropertyChanged(string name)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            if(!control.IsDisposed)
                control.BeginInvoke(handler, this, new PropertyChangedEventArgs(name));
        }
    }
}

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}
  • 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-13T07:08:32+00:00Added an answer on May 13, 2026 at 7:08 am

    I suspect that when a PropertyChanged event occurs, the DataGridView refreshes all cells, or perhaps only cells in the row that changed (does it happen when you’re editing another row ?), losing all uncommited changes.

    If you can intercept the event before the DataGridView refreshes the cells, you could save the uncommited changes away to restore them after the refresh. But that would be an ugly workaround…

    Did you ask on the MSDN forums ? Maybe someone from MS could give you a more useful answer

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

Sidebar

Ask A Question

Stats

  • Questions 291k
  • Answers 291k
  • 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 In Sql Server: SELECT TOP 3 item_id, COUNT(*) as itemcount… May 13, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer You can make the second argument to replace a function:… May 13, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer It appears you must differentiate between the tables. Try with:… May 13, 2026 at 6:02 pm

Related Questions

I was testing on a customer's box this afternoon which has Windows Vista (He
I have a C# Windows Forms application, whose prototype was created on SQL Server
I have a windows forms application which serves as a sort of administrative module
I'm new to C# and I am using VS08, I have created a form
Time ago I created an application which has some buttons in the form. Now

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.