Results 1 to 10 of 10

Thread: [RESOLVED] Binding Confusion

Threaded View

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Resolved [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...

    Quote 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:
    1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    2.  
    3.         'create the bound table. This will come from mySQL server
    4.         Dim dt As New DataTable
    5.         dt.Columns.AddRange({New DataColumn("whatToDo")})
    6.         dt.Rows.Add("have")
    7.         dt.Rows.Add(" a ")
    8.         dt.Rows.Add("beer")
    9.         dt.Rows.Add(" ;) ")
    10.         dt.AcceptChanges()
    11.  
    12.  
    13.         'set the bindings....
    14.         BindingSource1.DataSource = dt
    15.         Me.BindingNavigator1.BindingSource = BindingSource1
    16.         Me.TextBox1.DataBindings.Add("Text", BindingSource1, "whatToDo")
    17.  
    18.  
    19.  
    20.  
    21.     End Sub
    22.  
    23.  
    24.     Private Sub BindingNavigatorMoveNextItem_Click(sender As Object, e As EventArgs) Handles    BindingNavigatorMoveNextItem.Click
    25.  
    26.  
    27.         Me.Validate()
    28.  
    29.  
    30.         Dim row As DataRow = DirectCast(BindingSource1.Current, DataRowView).Row
    31. Dim value As String = row("whatToDo").ToString
    32.         Dim rowState = row.RowState
    33.  
    34.  
    35.  
    36.  
    37.         Debug.Print(String.Format("{0}     {1}", value, rowState))
    38.  
    39.  
    40.  
    41.  
    42.     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
  •  



Click Here to Expand Forum to Full Width