CodexBloom - Programming Q&A Platform

DataGridView Not Displaying Updated Data After Binding in WinForms C#

👀 Views: 79 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-13
winforms datagridview bindinglist C#

I'm stuck on something that should probably be simple. I've encountered a strange issue with Hey everyone, I'm running into an issue that's driving me crazy... I've looked through the documentation and I'm still confused about I'm having trouble with a `DataGridView` control in a WinForms application. I've bound the `DataGridView` to a `BindingList<T>` that is supposed to update automatically when the underlying data changes. However, after making changes to the list, the `DataGridView` does not refresh to show the new data unless I manually call `Refresh()`. Here's the code for my form where I set up the `DataGridView`: ```csharp public partial class MyForm : Form { private BindingList<MyData> myDataList; public MyForm() { InitializeComponent(); myDataList = new BindingList<MyData>(); dataGridView1.DataSource = myDataList; } private void UpdateData() { myDataList.Add(new MyData { Id = 1, Name = "Item 1" }); // I expect the DataGridView to show this new item automatically } } ``` I've ensured that `MyData` implements `INotifyPropertyChanged`, but it seems that the scenario lies with the `BindingList` not notifying the `DataGridView` of changes to its collection. I've tried calling `ResetBindings()` on the `BindingSource` and also toggling the `DataGridView`'s `DataSource`, but nothing seems to work. Is there a way to ensure that the `DataGridView` updates automatically when the `BindingList` changes, or do I need to handle this manually? Any insights would be greatly appreciated! For context: I'm using C# on Windows. This issue appeared after updating to C# LTS. What would be the recommended way to handle this? I'm developing on Ubuntu 20.04 with C#. Am I missing something obvious? This issue appeared after updating to C# 3.10. Hoping someone can shed some light on this.