I have a bound datagridview and a dataset with tables.

I have two sets of comboboxes bound to the same field "Restaurant" in the tables (mirroring each other).

In the "NewEmployeeRestaurant" combobox I change the value and it reflects in the datagridview. I can shoot around clicking all over the datagridview on other employees, but when I return to the employee I changed, the value remains what I changed it to. All is good in the world.

However, when I go to the "EmployeeRestaurant" combobox with the same settings, I change the value and it is reflected in the datagridview. So far so good. But when I go to another employee then click back on that employee I changed, the datagridview still shows the new value but the combobox is empty! NOT COOL!

I went so far as to try to copy the combobox object that IS working and use it, but I get the same issue. I'm dumbfounded. Any ideas?

Thanks!

The comboboxes don't matter, it's the code that handles them. Check the code that handles the events on the comboboxes (either focus and lost focus or value changes) and the datagridview. I'm betting that you've got a logical error in your design or you are reading from your db instead from your dataset.

That's the issue; I used the VS wizards to add these controls, so I never did any coding for them. I have no focus or value change events for these objects. And since I always use wizards to create these objects, I'm afraid I'm not very good at delving into the auto-generated code behind their events...

I have done some investigation and found that the selection in the combobox does write to the table. However, when I push the binding source back to that position (index), it wipes out the selection in the combobox! Why in the world would it do this???

Solved: I believe this to be some kind of bug in VS. I had a groupbox with other bound comboboxes tied to the same table. I had made the groupbox visible = false for user functionality reasons. When I defaulted that groupbox to visible = true, the original combobox worked.

I am maddened by these VS bugs but grateful for the tool in general. I hope this helps someone in the future.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.