WinForms: Why is my ComboBox not updating the selected value after data binding?
I've hit a wall trying to I'm writing unit tests and I tried several approaches but none seem to work. I've been banging my head against this for hours. I tried several approaches but none seem to work. I've been working on a WinForms application using .NET Framework 4.8, and I encountered an issue where the `ComboBox` is not updating its selected value after I bind it to a list of objects. I have a `ComboBox` that should display a list of `Customer` names, and the selected customer should be set based on the current `Order`. Here is how I'm setting it up: ```csharp public class Customer { public int Id { get; set; } public string Name { get; set; } } public class Order { public int CustomerId { get; set; } } private List<Customer> customers = new List<Customer>(); private Order currentOrder = new Order(); private void Form1_Load(object sender, EventArgs e) { customers.Add(new Customer { Id = 1, Name = "Alice" }); customers.Add(new Customer { Id = 2, Name = "Bob" }); comboBoxCustomers.DataSource = customers; comboBoxCustomers.DisplayMember = "Name"; comboBoxCustomers.ValueMember = "Id"; currentOrder.CustomerId = 2; comboBoxCustomers.SelectedValue = currentOrder.CustomerId; // This line doesn't seem to work } ``` Despite attempting to set the `SelectedValue` right after binding the `DataSource`, it doesnβt seem to update the `ComboBox`. I also ensured that `currentOrder.CustomerId` is indeed set to a valid `Id` from the `customers` list before assigning it to `SelectedValue`, but the `ComboBox` still displays the first entry instead of "Bob". I also tried calling `comboBoxCustomers.Refresh()`, but that didn't help either. I've checked that the `ValueMember` and `DisplayMember` are set correctly. Is there something I'm missing, or is there a specific timing issue with data binding in WinForms that I should be aware of? Any suggestions would be greatly appreciated! For context: I'm using C# on Ubuntu. Is there a better approach? I'd really appreciate any guidance on this. Any help would be greatly appreciated! This issue appeared after updating to C# 3.11. Am I approaching this the right way? I'm using C# stable in this project. What am I doing wrong? The stack includes C# and several other technologies. Is there a better approach?