Convert generic list to dataset in C#(在 C# 中将通用列表转换为数据集)
问题描述
我有一个通用对象列表.每个对象有 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# 中将通用列表转换为数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中将通用列表转换为数据集
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
