有没有一种简单的方法可以通过 DataTable 填充 ListView?
DataGridView
有一个属性“DataSource”,可以简单地分配给 DataTable
来填充它。这意味着我们不必担心 DataTable 中的名称/列数。
但是,我还没有找到填充 ListView
的类似方法。似乎您需要知道 DataTable 有多少列以及每列的名称才能执行此操作,这使得它变得更加困难。
谁能建议一种简单的方法来填充 ListView
就像我们使用 DataGridView
一样?
The DataGridView
has a property "DataSource" that can simply be assigned to a DataTable
to populate it. This means we don't have to worry about the names/number of columns in the DataTable
.
But, I haven't found a similar way of populating a ListView
. It seems that you need to know how many columns the DataTable
has and the names of each in order to do this, making it much more difficult.
Can anyone suggest an easy way to populate a ListView
like we can with a DataGridView
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还可以在 - 处找到排序等内容
http://www.akadia.com/services/dotnet_listview_sort_dataset.html
修改 -
Find sorting etc also at -
http://www.akadia.com/services/dotnet_listview_sort_dataset.html
Modified -
ObjectListView —— .NET WinForms ListView 的开源包装器 —— 有一个
DataListView
子类正是这样做的。您可以给它一个数据源(可以是
DataView
,数据表
,数据集
,DataViewManager
,或BindingSource
),它会自动创建列并填充行,以创建功能齐全的列表视图。你只需要一行代码:ObjectListView -- an open source wrapper around a .NET WinForms ListView -- has a
DataListView
subclass which does exactly this.You can give it a data source (which can be a
DataView
,DataTable
,DataSet
,DataViewManager
, orBindingSource
), and it will auto create columns and fill in the rows, to make fully functional list view. You just need one line of code: