DVader Posted October 3, 2006 Posted October 3, 2006 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? Quote
IUnknown Posted October 7, 2006 Posted October 7, 2006 ... 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! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.