问题描述
我有一个通用对象列表.每个对象有 9 个字符串属性.我想将该列表转换为可以传递给 datagridview 的数据集......这样做的最佳方法是什么?
I have a Generic list of Objects. Each object has 9 string properties. I want to turn that list into a dataset that i can pass to a datagridview......Whats the best way to go about doing this?
推荐答案
你试过直接绑定列表到datagridview吗?如果没有,请先尝试,因为它会为您节省很多痛苦.如果您已经尝试过,请告诉我们出了什么问题,以便我们更好地为您提供建议.数据绑定根据数据对象实现的接口为您提供不同的行为.例如,如果你的数据对象只实现了IEnumerable
(例如List
),你会得到非常基本的单向绑定,但是如果它实现了IBindingList
以及(例如BindingList
、DataView
),那么你就得到了双向绑定.
Have you tried binding the list to the datagridview directly? If not, try that first because it will save you lots of pain. If you have tried it already, please tell us what went wrong so we can better advise you. Data binding gives you different behaviour depending on what interfaces your data object implements. For example, if your data object only implements IEnumerable
(e.g. List
), you will get very basic one-way binding, but if it implements IBindingList
as well (e.g. BindingList
, DataView
), then you get two-way binding.
这篇关于在 C# 中将通用列表转换为数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!