简体   繁体   中英

Is there a way to know which rows have been modified in a DataGridView in C#

I am working with a big database in slow computers and all the rows are shown and are modificable. The problem is when the user hits Save I have to UPDATE 300 rows in MySQL because I don't know which rows have been modified and which ones haven't.

Is there a way to know which rows the user has modified?

Thanks

As Ola suggested, you could use the CellValueChanged event (or whatever other changed event you would like).

Since your DGV is not bound you can keep track of what has changed based on the changed events, and when your users click Save you could only update the rows that were changed.

You could keep track using something simple like a List of the row numbers that were modified (and therefore just loop through those rows during save) or using something more complex if you want to make the data structures and logic to represent individual changes.

It is hard to give more detail without seeing your code but the basic theory should be pretty easy to apply.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM