如何绑定POCO对象列表到Windows窗体DataGrid [英] How to bind a list of POCO objects to Windows Forms DataGrid
问题描述
我没有做任何窗口之前的形式,我试图创建一个简单的应用程序对我来说,我查看消息记录的服务。
I've not really done any windows forms before, and I am attempting to create a simple app for me to view my message logging service.
我以为要做到这一点最简单的方法是用一个DataGridView控制。你如何将对象绑定到它的简单列表,并有标题栏生成等汽车?
I thought the simplest way to do this would be with a DataGridView control. How do you bind a simple list of objects to it and have the column headings etc auto generated?
我迄今所做的这一点,它与标题而造成的列没有。行/数据
I have done this so far and it creates the columns with headings but no rows/data.
List<Log> logs = loggingRepo.LoadAll();
logGrid.DataSource = logs;
我本来期望那里是一个 logGrid.DataBind()
就像在ASP.NET名单的意见,但似乎没有被一种方法。
I would have expected there to be a logGrid.DataBind()
method like list views in ASP.NET but there doesn't seem to be one.
推荐答案
有没有数据绑定,数据源的设置立即生效。
There's no databind, the setting of DataSource takes place immediately.
绑定到波苏斯不是很大,虽然,你最终为用户不到最佳体验。我想包装在的BindingList日志收集,应该使一些基本的分类和过滤。
Binding to POCOs isn't great though, you end up with a less than optimal experience for the user. I'd wrap the logs collection in a BindingList, that should enable some basic sorting and filtering.
这篇关于如何绑定POCO对象列表到Windows窗体DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!