DataGridView Edited Row

T

Terry Olsen

How can i tell if a row in my DataGridView has been edited? I'm loading a
DataTable with ID3 information from MP3 files and using that as the
datasource for the DataGridView. I'm letting the user edit the information
in the grid and when the user has finished, he clicks the "Update" button.
Then I update the ID3 information in each MP3 file with the data from the
grid. However, if the grid has hundreds of files in it, this can take a
while.

I'd like to only update a file if its information has been edited. I didn't
find a property like "IsRowDirty" for the grid.

Thanks for any help.
 
P

Paul Evans

Terry Olsen said:
How can i tell if a row in my DataGridView has been edited? I'm loading a
DataTable with ID3 information from MP3 files and using that as the
datasource for the DataGridView. I'm letting the user edit the information
in the grid and when the user has finished, he clicks the "Update" button.
Then I update the ID3 information in each MP3 file with the data from the
grid. However, if the grid has hundreds of files in it, this can take a
while.

I'd like to only update a file if its information has been edited. I
didn't find a property like "IsRowDirty" for the grid.

Thanks for any help.
Is there a Changed or TextChanged event for the DataGridView?
A method I used in a project could be adapted here, you add a 0 width column
to the DataGridView when you create it.
If the row is changed, set it to have a value, then later on when you save,
hack through the DataGridView.
If the flag column has a value, save it; if not, don't.
Another approach would be to store the original value in the flag column
when you populate the DataGridView.
Check that the 2 are the same when you go to save, if not, it's changed...
It would be harder in this case, as you're comparing several bits of
information for a change, but we can work round this.
If you have Column1, Column2 & Column3, Flag could contain
Column1|Column2|Column3, and we can play like that.
It would help, of course, if the delimiter is something that is illegal in
IDv3.

Hope some (or even better, all) of this helped.

--Paul Evans
SHL Computing
 
C

ClayB

One way you can get the changed information is to directly use the
datatable by calling DataTable.GetChanges. This will give you a
datatable that holds the changed rows. (Depending upon how you are
initially loading the Datatable, you may need to call
DataTable.AcceptChanges right after the table is initially loaded so
GetChanges will only return your user changes, and not the changes
that came about as a result of the initial load.)

===================
Clay Burch
Syncfusion, Inc.
 
R

RobinS

There is an underlying property on each row of the DataTable that tells you
if the record has been added, modified, or deleted. It stays active until
you push the changes down to your data source.

How are you doing your update? If you are calling the Update method on a
tableadapter or SqlAdapter, it only updates the rows that have been
modified.

Robin S.
 

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