使用 DataGridView.DataSource 显示单个对象
我习惯于使用以下格式的 DataGridView 控件显示多个对象。
ID Name Address [...]
ID1 Name1 123 street [...]
ID2 Name2 456 street [...]
这对于对象、属性和 BindingList
来说很简单。
我希望我的数据“旋转”90 度,以便网格显示一个键:值对,例如
FieldName Value
ID ID1
Name Name1
Address 123 street
是否可以通过将某种列表/字典/其他内容绑定到数据源来实现?我正在检查这种方法,因为对象属性获取/设置使得处理数据更改比处理从 DataGridView 导出的无数事件要容易得多
I'm used to display multiple objects with a DataGridView control in the following format
ID Name Address [...]
ID1 Name1 123 street [...]
ID2 Name2 456 street [...]
This is simple to do with objects, properties and a BindingList<>
.
I'd like my data to be "rotated" 90 degrees so that the grid displays a key:value pair such as
FieldName Value
ID ID1
Name Name1
Address 123 street
Is this possible to achieve by binding some kind of list/dictionnary/other to the DataSource? I'm checking this approach because the object properties get/set makes it MUCH easier to handle data changes than handling a gazillion events exported from the DataGridView
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 Windows 窗体应用程序吗?您是否考虑过使用 PropertyGrid?在我看来,这似乎是解决您的问题的自然选择,除非您正在开发 ASP.Net 应用程序。
Is this a Windows Forms application? Have you considered using a PropertyGrid? It seems to me to be the natural choice for your problem unless you're doing an ASP.Net app.
在我看来,您只想使用 FormView 或 DetailsView? (主要区别是DetailsView 为您提供自动生成的表,而FormView 则由您定义模板)
如果这些都不是答案,您能解释一下为什么您需要特别坚持使用DataGridView 吗?
It sounds to me like you would want to just use FormView or DetailsView? (Main difference is DetailsView gives you auto generated tables, with FormView you define a template)
If those aren't the answer, can you explain why you need to stick with DataGridView in particular?