
Bindingd Dataset to Textbox appears flawed.
If you want to know what EndCurrentEdit does, I'll tell you. You have
selected one of the rows of the table to edit. All the data is shown in the
textboxes. You edit the fields you wish, but during that time, the row is in
editing state. If you want to save them, you have to end this editing with
EndCurrentEdit. When you change selected row, it automatically call it.
Here's a tip about binding. If you save data back to the datasource when you
change row, close the form or anything, and you call EndCurrentEdit, if you
close the form, the control you just edited who still have the focus will
not save because it's still in editing and the data haven't been validated.
When you close, you can change the focus to another control before saving.
Quote:
> It appears to me that binding to textboxes with a dataset is iffy at best.
I
> have a test project that shows what I have been looking at. This is a set
> of screens that accesses the Pubs/Publishers table. I will be glad to send
> this project (30M zipped) to anyone who wants to take a look at it, just
let
> me know.
> What I have found is this:
> Form1: straightforward grid tied to all data in the table, seems to work
ok.
> Form2: grid with an adapter that loads only a single row, seems to work ok
> too.
> Form3: textbox implementation with all boxes bound to dataset. Changes to
> the State field (or any field) are not saved unless you update the value
in
> the dataset in txtState_Validating. If you update the value in
> txtState_textchanged then you get strange behavior (see comments in code)
> DataForm1: illustrates binding to textboxes as the DataForm wizard sees
it.
> This seems to work but you must move from a changed row to another row
> before clicking update or the changes don't take.
> Form4: A repeat of Form3 but now I have added a line
> Me.BindingContext(PublishersDS1, "publishers").EndCurrentEdit()
> to the save button. This is what I noticed the DataForm1 wizard generated
> code was doing when you moved from row to row. This now works without any
> binding code in _validating or _textchanged. I would love to have an
> explanation for this!
> Form5: A repeat of Form3 but with binding not set on the "State" field. I
> have handled the binding with code in _validating and _textchanged. This
> also seems to work fine.
> My conclusion: I think one (or more of the following is true:)
> The binding to textbox has a bug.
> The explanation of what is going on is inadequate.
> MS needs to provide real world examples of this stuff.
> Handling the binding with my own code seems safest for now as I have no
idea
> what the BindingContext...EndCurrentEdit is doing.
> I still haven't got a clue what I am doing.
> --
> Barry Fitzgerald