且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取数据网格中的所有行值

更新时间:2023-10-19 11:28:58

不要从 DataGridView获取数据.有一个数据层,无论它是什么,将其绑定到视图并从数据层而不是从UI获取数据.即使您不使用数据绑定,您的方法也应该相似:您应该从数据层填充UI,并且对UI的编辑操作应更新数据层.其他所有内容,例如数据持久性,报告,打印,与其他方的数据交换,都应来自数据层.即使对于大多数简单的应用程序.

如果这种方法似乎不太明显,建议您学习并分析以下建筑模式( 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
Don''t get data from DataGridView. Have a data layer, whatever it is, bind it to the view and get data from the data layer, not from UI. Even if you don''t use data binding, your approach should be similar: you should have population of UI from the data layer and editing action on UI should update data layer. Everything else, such as data persistence, reports, printing, data exchange with other parties should come from the data layer. Even for most simple applications.

If this approach does not seem apparent, 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