D
DJM
I have a DataSet. In it, there is a DataTable. When I change the value of
a column on this particular table, I want to change the values of two other
fields on this table.
I have an event tied to ColumnChanged (e is DataColumnChangeEventArgs).
When I change the value, first I check to see if (e.Column.ColumnName ==
"DesiredColumn" && e.ProposedValue != e.Row[e.Column,
Data.DataRowVersion.Current]) and only act if that is true. If I change the
value from 4 to 5, then it sees that ProposedValue 5 is not equal to Current
value 4 and processes correctly. However, if I then change it back to 4, it
compares ProposedValue 4 to what it gets for Current value, 4.
This is how I've been testing it. I have a VB app that binds the DataSet to
a DataGrid, which I then use to type in changes and view the results. If I
type in a "5" in the column specified and tab to the next field, the event
handler fires just as I would expect. However, if I tab back and then type
a "4", the Current value is still at 4 and the ProposedValue is also 4, and
so the event procedure aborts. If I enter a new value and cursor DOWN
instead of right, to go to a different row, the Current value appears to get
updated, as when I cursor back up and enter a 4, the Current value has
indeed changed to 5 and the procedure continues normally, recognizing the
change.
It would almost make sense, then, to use the RowChanged event instead of the
ColumnChanged event, as it appears the Current value gets updated when the
entire row edit is complete. However, that doesn't work out in this case,
because in the arguments to the RowChanged event, there are no more Proposed
values. RowChanging has Proposed values, but you can't update data in the
midst of a RowChanging event.
So, what can I expect when changing in code? If I do a
dsData.Tables[0].Rows[0]["DesiredColumn"] = 5, what events will get fired?
and how can I make sure that a RowChanged event *does* fire so if I later do
a dsData.Tables[0].Rows[0]["DesiredColumn"] = 4, the procedure doesn't
abort? I don't want to do an AcceptChanges, because I'm not sure at that
point that I want the changes accepted.
a column on this particular table, I want to change the values of two other
fields on this table.
I have an event tied to ColumnChanged (e is DataColumnChangeEventArgs).
When I change the value, first I check to see if (e.Column.ColumnName ==
"DesiredColumn" && e.ProposedValue != e.Row[e.Column,
Data.DataRowVersion.Current]) and only act if that is true. If I change the
value from 4 to 5, then it sees that ProposedValue 5 is not equal to Current
value 4 and processes correctly. However, if I then change it back to 4, it
compares ProposedValue 4 to what it gets for Current value, 4.
This is how I've been testing it. I have a VB app that binds the DataSet to
a DataGrid, which I then use to type in changes and view the results. If I
type in a "5" in the column specified and tab to the next field, the event
handler fires just as I would expect. However, if I tab back and then type
a "4", the Current value is still at 4 and the ProposedValue is also 4, and
so the event procedure aborts. If I enter a new value and cursor DOWN
instead of right, to go to a different row, the Current value appears to get
updated, as when I cursor back up and enter a 4, the Current value has
indeed changed to 5 and the procedure continues normally, recognizing the
change.
It would almost make sense, then, to use the RowChanged event instead of the
ColumnChanged event, as it appears the Current value gets updated when the
entire row edit is complete. However, that doesn't work out in this case,
because in the arguments to the RowChanged event, there are no more Proposed
values. RowChanging has Proposed values, but you can't update data in the
midst of a RowChanging event.
So, what can I expect when changing in code? If I do a
dsData.Tables[0].Rows[0]["DesiredColumn"] = 5, what events will get fired?
and how can I make sure that a RowChanged event *does* fire so if I later do
a dsData.Tables[0].Rows[0]["DesiredColumn"] = 4, the procedure doesn't
abort? I don't want to do an AcceptChanges, because I'm not sure at that
point that I want the changes accepted.