When does "Current" value update?

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.
 
C

Cor Ligthert

Hi DJM,

A lot of text, however first of all forget a while the "accept changes"
because the way you write about it is wrong. Acceptchanges you can use by
instance when you want to set in the dataset that you did a complete correct
update, while you did not.

With the datagrid the changes comes active when there is a row change in the
datagrid (or better to say the currencymanager position has changed).

When you want to do more, you can extend your datagrid by instance with
datagridtextboxes or somethjng like that, which can hold events like click
down, key up etc.

There is the bindingcontext(dataset).endcurrentedit, which forces the data
from the grid in the underlaying datasource. (This to remember, because you
need it almost for sure when you do an update).

Some people use the event "currentcellchanged" from the datagrid to do
things direct as I told you above.

You can say this behaviour is wrong, however than other people will say that
your wished behaviour can be seen as wrong.

I hope this helps

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top