Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm developing a form that has five textboxes that I bind to a DataTable in a DataSet.

 

Private Sub BindEvent()

       Try
           Me.txtEventNbr.DataBindings.Add(New Windows.Forms.Binding("text", dsSafety.Tables("Event"), "EventID"))
           Me.txtAccidentLocation.DataBindings.Add(New Windows.Forms.Binding("text", dsSafety.Tables("Event"), "LocationDesc"))
           Me.txtAccidentDate.DataBindings.Add(New Windows.Forms.Binding("text", dsSafety.Tables("Event"), "EventDate"))
           Me.txtAccidentTime.DataBindings.Add(New Windows.Forms.Binding("text", dsSafety.Tables("Event"), "EventTime"))
           Me.txtAccidentDesc.DataBindings.Add(New Windows.Forms.Binding("text", dsSafety.Tables("Event"), "EventDesc"))
       Catch ex As Exception
           MessageBox.Show(ex.Message & vbCrLf & vbCrLf & ex.StackTrace, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
       End Try

   End Sub

 

If I change a value of one of the textboxes on the form I expect the Rowstate property for the DataTable the textbox is bound to tobe change to Modified, but that isn't happening. It still indicates that the RowState is Unmodified. Though if I check the value of the column in my DataTable it has the value that I keyed into the textbox (using a messagebox behind a button).

 

I tried adding some additional logic to force an EndCurrentEdit when I change the value of the textbox, but the RowState still says Unmodified.

 

Private Sub txtAccidentLocation_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAccidentLocation.LostFocus

       Try
           Me.BindingContext(dsSafety).EndCurrentEdit()
       Catch ex As Exception
           MessageBox.Show(ex.Message & vbCrLf & vbCrLf & ex.StackTrace, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
       End Try

   End Sub

 

Any ideas on why the Rowstate of the DataTable doesn't change to Modified when changing the value in the textbox?

Posted
...

Any ideas on why the Rowstate of the DataTable doesn't change to Modified when changing the value in the textbox?

The reason is because BeginEdit has been implicitly called when you edit the textbox and EndEdit hasn't been called, so RowState remains Unchanged. If you call EndEdit, RowState will change to Modified.

 

While in edit mode, to find out if a value has been changed, you can check for a proposed version in the DataRow, e.g., .Row.HasVersion(DataRowVersion.Proposed).

 

Hope this helps!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...