B
Brian Hoops
I have a windows forms datagrid and I would like to be able to recognize
when changes have been made in order to perform the update. I tried the
following, which works well, but only if the user changes rows at some
point. If they enter the grid, change a cell, and then click close it does
not see the change. The same holds true if they enter the grid, change a
cell, arrow right or left to a different cell and change that value. If
they arrow up or down it sees the dataset as having changes.
What am I missing? I don't want to rely on the user having to press enter
or selecting a different row after making their update.
Thanks!
--------------------Code---------------------------------
Dim blnDataChanged As Boolean = False
Dim dt As DataTable
dt = ds.Tables("tblCIP").GetChanges
If dt Is Nothing Then
Return False
Else
Dim Row As DataRow
Dim intColumn As Integer
For Each Row In dt.Rows
Select Case Row.RowState
Case DataRowState.Added
blnDataChanged = True
Case DataRowState.Deleted
blnDataChanged = True
Case DataRowState.Modified
For intColumn = 0 To dt.Columns.Count - 1
If Not IsDBNull(Row(intColumn, DataRowVersion.Original)) And Not
IsDBNull(Row(intColumn, DataRowVersion.Current)) Then
If Row(intColumn, DataRowVersion.Original) <> Row(intColumn,
DataRowVersion.Current) Then
blnDataChanged = True
Exit For
End If
End If
Next
End Select
If blnDataChanged Then Exit For
Next
Return blnDataChanged
end If
when changes have been made in order to perform the update. I tried the
following, which works well, but only if the user changes rows at some
point. If they enter the grid, change a cell, and then click close it does
not see the change. The same holds true if they enter the grid, change a
cell, arrow right or left to a different cell and change that value. If
they arrow up or down it sees the dataset as having changes.
What am I missing? I don't want to rely on the user having to press enter
or selecting a different row after making their update.
Thanks!
--------------------Code---------------------------------
Dim blnDataChanged As Boolean = False
Dim dt As DataTable
dt = ds.Tables("tblCIP").GetChanges
If dt Is Nothing Then
Return False
Else
Dim Row As DataRow
Dim intColumn As Integer
For Each Row In dt.Rows
Select Case Row.RowState
Case DataRowState.Added
blnDataChanged = True
Case DataRowState.Deleted
blnDataChanged = True
Case DataRowState.Modified
For intColumn = 0 To dt.Columns.Count - 1
If Not IsDBNull(Row(intColumn, DataRowVersion.Original)) And Not
IsDBNull(Row(intColumn, DataRowVersion.Current)) Then
If Row(intColumn, DataRowVersion.Original) <> Row(intColumn,
DataRowVersion.Current) Then
blnDataChanged = True
Exit For
End If
End If
Next
End Select
If blnDataChanged Then Exit For
Next
Return blnDataChanged
end If