How to change a DataRow inside an event handler?

  • Thread starter Thread starter DJM
  • Start date Start date
D

DJM

I have a dataset that includes a data table, Item, that has a LocationID
field on it. In the stored procedure I use to generate this dataset, I
include a Join on my Location table so that the Item table includes fields
like LocationName, LocationType, LocationSize, etc. for ease of display (I'm
binding to a data grid and want these location fields to be displayed
in-line with the Item row).

Now, the user has an opportunity to change the LocationID of the item row.
When that ID is changed, I want the other fields to update automatically. I
wrote some code that takes the updated LocationID and, first, searches the
rest of the table for an Item row with that LocationID (so I can get the
other fields from there instead of round-tripping to the database), or goes
to the database if no matching LocationID can be found. (The Location table
is huge; loading the entire thing into memory is not desirable.)

The problem is, I cannot change the other columns in a RowChanging event. I
can't use a RowChanged event, because then I cannot tell if a row has
changed because of the LocationID column. (It would also adversely affect
my attempt to scan the table for matching LocationIDs, since I'm looking for
a matching Current value, and the affected row itself's Current value is the
new LocationID.)

At least, this is how I understand my situation now. What can I do?
 
Ok, it would appear I've sort of answered my own question, but another one
came up.

The Column Changed event gives me access to the current and proposed values,
and I can change other columns and rows in the process (an Item can be
linked to other records that have a LocationID, so I needed to update those
rows and tables whenever an Item row changed; it works great now). However,
it seems to have another issue.

In the ColumnChanged event handler, I check the column's name to see if it
is "LocationID". If so, I call another function (which takes the affected
DataRow as a parameter) to update the other columns. If I set a breakpoint
in that function, it works great (aside from having to hit 'F5' to get it
going). If I clear the breakpoint and let it run, it doesn't appear to
work. Any ideas?
 
I hope talking to one's self is not a sign of severe psychological problems.

The problem was not quite what I had described, so I'm going to start a
whole new thread and pretend this one doesn't exist.
 
Back
Top