|
-
Nov 2nd, 2016, 05:14 PM
#1
[RESOLVED] Binding Confusion
Hi all,
I have the following code on a form. It uses a Binding Navigator, Binding Source and a Text Box. In the load event, I create a table and set bindings. Everything binds correctly, and the Text Box text changes when I use the navigator.
In the navigator's MoveNext button click handler I fetch the binding source's current row and display the row's value which is bound to the text box. I also output the row's state.
Immediately after the form loads, the text box says "have". If I change it to "must have" and then navigate to the next record, this is what is output to the debug window...
 Originally Posted by Console Window
must have Unchanged
So the row value is now "Must have", but it was "have" so it has changed yet the row state is unchanged. If I then navigate back to the first record then navigate forward again, the row state finally changes.
So if the row value is different, why is it not reflected in the rowState?
The code; add a binding navigator, binding source and a text box to a form and drop it in...
vb.net Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'create the bound table. This will come from mySQL server Dim dt As New DataTable dt.Columns.AddRange({New DataColumn("whatToDo")}) dt.Rows.Add("have") dt.Rows.Add(" a ") dt.Rows.Add("beer") dt.Rows.Add(" ;) ") dt.AcceptChanges() 'set the bindings.... BindingSource1.DataSource = dt Me.BindingNavigator1.BindingSource = BindingSource1 Me.TextBox1.DataBindings.Add("Text", BindingSource1, "whatToDo") End Sub Private Sub BindingNavigatorMoveNextItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorMoveNextItem.Click Me.Validate() Dim row As DataRow = DirectCast(BindingSource1.Current, DataRowView).Row Dim value As String = row("whatToDo").ToString Dim rowState = row.RowState Debug.Print(String.Format("{0} {1}", value, rowState)) End Sub
The whole reason for this is so that I can update the data base if and when a record has changed rather than after the form is closed. If there is a better way, please let me know.
thanks for looking
Kevin
Last edited by kebo; Nov 2nd, 2016 at 05:47 PM.
Reason: removed superfluous code
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|