Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding Source Issues When Changes Made in DataGridView vs Textbox

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
Having trouble with a binding source.
Here is the code where ds is the sdataset, bsPhysician is the dataset and dgvPhysician is my datagridview.
Code:
bsPhysician.DataSource = ds.Tables("dtPhysician")
dgvPhysician.DataSource = bsPhysician
Here is the code I have for saving the changes mafe in a datagridview.
Code:
Dim table As DataTable = ds.Tables("dtPhysician")
Dim dr As DataRow
If Not ds.HasChanges Then
  MessageBox.Show("No changes have been made.", _
    "Attention", _
    MessageBoxButtons.OK, _
    MessageBoxIcon.Exclamation, _
    MessageBoxDefaultButton.Button1)
  Return
End If
Dim changedRecordsTable As DataTable = table.GetChanges()
ChangedRecordCount = changedRecordsTable.Rows.Count
.........
'Rest of code with dtaadapter update
This works when I make changes in the datagridview, but I'm concerned about checking the ds instead of the binding source for changes. Not sure if that is the correct wy to do it.
I'm also a little confused because if I use the same code and bind a text box to the binding source like this and make changes in the textbox and not the datagridview, Then it does not recognize that a change was made. ds.HasChanges returns False. The datagridview and textbox are on separate tabs in a tabcontrol and I only let the user make changes to one row at a time.
Code:
txtPatientNbr.DataBindings.Clear()
txtPatientNbr.DataBindings.Add("Text", bsPhysician, "PatientNbr")
txtPatientNbr.MaxLength = 10
Also if I bypass the HasChanges code then I get an error when it hits the "ChangedRecordCount =" command. The error is "System.NullReferenceException: Object reference not set to an instance of an object". Confused! Any help will be appreciated. I've tried
Code:
Dim hasChanged As Boolean
hasChanged = DirectCast(bsPhysician.Current, DataRowView).Row.HasVersion(DataRowVersion.Proposed)
but don't know how to get just the rows that changed to use in the dataadapter update.



Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top