Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am creating a VB.Net Win-Form Application.

I have two identical Datagridviews. First datagridview have some rows and Second datagridview empty.

'on button click
I want to copy/update all the rows/cell values from First Datagridview to Second Datagridview. Adding/Removing rows in First Datagridview must update rows in Second Datagridview.

Main principles is this: don't copy data from one control to another control.

Instead, create a (tiny) data layer. Populate all controls from data. When a control event is suppose to change some data, do it on your data layer, then send a notifications to other controls used by all controls to re-populate or adjust data presentation accordingly. That means, you control should play the role of listeners or the observable data structure. Even if you don't introduce those concept explicitly (which is recommended though), the design of the code should follow this or similar pattern.

I suggest you learn and analyze applicability of the following architectural patterns ([^]):

MVVM — Model View View Model,[^],

MVC — Model-View-Controller,[^]),

MVA — Model-View-Adapter,–view–adapter[^],

MVP — Model-View-Presenter,[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

Share this answer
if structure is same for both then
you need to get that row and do clone to another row object and add second object to blank datagridview.
Share this answer

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