T
Tom Archer
Here's my situation:
* I have an SDI application where the main view is a
listview of employees
* When a new employee is added, I create the DataRow, add
that row to the data table's
DataRowCollection and then insert the relevant data into
the list view. However, as I do not
have the primary key (which is autoincrement) I specifiy a
value of -1.
* When the user selects a newly added item to delete, I
use the DataTable::Find method. However,
obviously that doesn't work for my new records that do not
have their primary keys from the data
store yet.
* Therefore, I'm trying to figure out how to locate the
row the user wants to delete.
I have come up with one solution, but it's kind of of a
kludge and I wanted to verify if there
wasn't an easier way:
1) For each new record, get the hash code associated with
the new DataRow and store that as item
data for the listview entry.
2) OnDelete -
if (-1 != EmployeeID) // record is not new
use the DataTable::Find method to locate the DataRow
call DataRow:elete
else // record is new
use the Select method with First Name and Last Name to
get a DataRow array
if rows returned == 1
call DataRow:elete on first (and only) row in array
else
get stored hashcode for item
enumerate DataRow array looking for row that has same
hashcode and delete row
This works, but seems like a lot of work to delete a
record and so I want to verify with you folks that this is
the only way (within the context of my application) to
find and delete a new row from a disconnected dataset.
* I have an SDI application where the main view is a
listview of employees
* When a new employee is added, I create the DataRow, add
that row to the data table's
DataRowCollection and then insert the relevant data into
the list view. However, as I do not
have the primary key (which is autoincrement) I specifiy a
value of -1.
* When the user selects a newly added item to delete, I
use the DataTable::Find method. However,
obviously that doesn't work for my new records that do not
have their primary keys from the data
store yet.
* Therefore, I'm trying to figure out how to locate the
row the user wants to delete.
I have come up with one solution, but it's kind of of a
kludge and I wanted to verify if there
wasn't an easier way:
1) For each new record, get the hash code associated with
the new DataRow and store that as item
data for the listview entry.
2) OnDelete -
if (-1 != EmployeeID) // record is not new
use the DataTable::Find method to locate the DataRow
call DataRow:elete
else // record is new
use the Select method with First Name and Last Name to
get a DataRow array
if rows returned == 1
call DataRow:elete on first (and only) row in array
else
get stored hashcode for item
enumerate DataRow array looking for row that has same
hashcode and delete row
This works, but seems like a lot of work to delete a
record and so I want to verify with you folks that this is
the only way (within the context of my application) to
find and delete a new row from a disconnected dataset.