I have a vb.net application that talks to a Microsoft Access backend. On one form I have a datagridview
, and beneath that a number of "detail" fields; these were generated by dragging onto the form, so there's autogenerated code, and it pretty much works: If I click on a row in the datagridview
, the detail fields show that data, and if I change the data (by typing) in any of the detail fields (these are textboxes
, comboboxes
, etc.) the data changes in the datagridview
.
NB - I've made the datagridview
read-only, so that all user changes must run through the detail fields, where I do a lot of consistency checking. So far, all good.
The problem that has arisen is that if I programmatically change some of the detail fields, that data doesn't show up in the datagridview. I want to do this if data is entered into certain fields - imagine someone entering birthdate, and I want to update an Age field (this is notional; that'd be silly, but the mechanism is the same). In that example I might set Agetextbox.text = "52"
or something, but that data doesn't show up in the datagridview. If I type "52" into that field the datagridview does update.
This is all happening before I push the data back out to the database - indeed I don't want to commit these changes until the user has filled in nearly all of the fields, or at least they're all valid - so it isn't an issue of updating the database and reading the data back in. It's merely an issue of having two (I thought) identically-bound controls show the same data.
A detail that might be important - the programmatic update works for the first 4 or 5 columns in the datagridview, then not for the rest of them. No error is thrown, but to me it is suspicious that the updating seems to proceed for a few fields and then stop. This is where I've been digging so far, with no luck.
I'll again try to dig into the autogenerated code to see if I can spot an answer, but I'd appreciate any wisdom anyone has.
It seems that a bindingsource.endedit() after the programmatic updates fixes the problem.