如何获取数据网格中的所有行值 [英] How to get all row values in a datagrid

查看:68
本文介绍了如何获取数据网格中的所有行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我需要在datagridview中获取所有行值,并将它们转换为字符串.该数据网格只有一列.例如,如果行值像:datagrid中的1 2 3

Hi guys! I need to get all the row values in a datagridview and convert them into a string. The datagrid has only one column. E.g if row values like: 1 2 3 in datagrid

推荐答案

不要从 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


这篇关于如何获取数据网格中的所有行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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