Click here to Skip to main content
15,938,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a big DataGridView, and for some reason I need to save the value of each cell as tag.
Now I use a loop to complete each cell one by one, but it wastes a lot of time because the DGV is large. Is there any way to speed up this work? Thanks.

What I have tried:

Use a loop to work it, but it wastes time.
Updated 15-Oct-22 21:23pm
Richard MacCutchan 16-Oct-22 3:26am    
"for some reason I need to save the value of each cell as tag."
Is it a good reason? There may be better ways to do what you really need.
Hu Christian 16-Oct-22 4:22am    
Because the attributes and some special purposes of each cell need to be exported to a file, and then re-imported or edited. So I use tag to store these parameters for every cell. It's a bit like a mini worksheet. Thanks.

1 solution

No, not really. To set each DataGridViewCell.Tag property you have to visit each and every Cell in the DataGridView individually, and copy the Value property to the Tag property.

Which is going to take time, with a big DataGridView.
And is a duplication of data.
And is a waste of time, memory, and processing power with no obvious benefit to anybody.

And that's before you even consider that a big DataGridView is normally a massive UI mistake in the first place because it's pretty much useless for the user: if you've got a small-but-still-too-big DataGridView that holds 1000 rows, it's going to take the user ages to find the row of data they are interested in. A big DataGridView makes that problem even worse, and most user - myself included - will immediately i=uninstall your app and start demanding their money back ...
Only ever present a Ui with up to 100 lines (and even that is pushing it): page it, search it, filter it - but just dumping the data on the user and going "You can sort that out" is a very poor idea!
Share this answer
Hu Christian 16-Oct-22 4:15am    
Thanks for your reply. You're right,it's not a good idea in a big DGV. I'll set a limit on the number of lines in this function. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900