将datagridview行复制到另一个datagridview中 [英] Copy datagridview row into another datagridview

查看:136
本文介绍了将datagridview行复制到另一个datagridview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在创建一个VB.Net Win-Form应用程序.

我有两个相同的Datagridviews.第一个datagridview有一些行,第二个datagridview为空.

''在按钮上单击
我想将所有行/单元格值从First Datagridview复制/更新到Second Datagridview.在第一个Datagridview中添加/删除行必须更新在第二个Datagridview中的行.

Hi,

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.

推荐答案

主要原理是:不要将数据从一个控件复制到另一个控件中控制.

而是创建一个(小)数据层.从数据填充所有控件.当控件事件要更改某些数据时,请在数据层上进行操作,然后向所有控件使用的其他控件发送通知,以相应地重新填充或调整数据表示.也就是说,您的控件应该扮演侦听器可观察数据结构的角色.即使您没有明确介绍这些概念(尽管建议这样做),代码的设计也应遵循这种或类似的模式.

我建议您学习并分析以下建筑模式的适用性( http://en.wikipedia .org/wiki/Architectural_pattern_(computer_science) [^ ]):

MVVM —模型视图视图模型,
http://en.wikipedia.org/wiki/Model_View_ViewModel [> http://en.wikipedia.org/wiki/Model-view-controller [ ^ ])),

MVA —模型视图适配器,
http://en.wikipedia.org/wiki/Model–view–adapter [ ^ ],

MVP —模型视图呈现器,
> http://en.wikipedia.org/wiki/Model-view-presenter [ ^ ].
请注意这些架构的动机.如果您了解它,就可以提出更好的设计思路.

-SA
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 (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

—SA


如果两个结构都相同,则
您需要获取该行并克隆到另一个行对象,然后将第二个对象添加到空白datagridview.
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.


这篇关于将datagridview行复制到另一个datagridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆