DataGridView绑定到第二级属性 [英] DataGridView Binding to Second Level Properties

查看:65
本文介绍了DataGridView绑定到第二级属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将DGV列绑定到类的第二级属性(即Client.Name)。


 


我看过Linda Liu的方法:http://blogs.msdn.com/b/msdnts/archive/2007/01/19/ how-to-bind-a-datagridview-column-to-a-second-level-property-of-data-source.aspx


这个看起来喜欢它会起作用,但是我想把它变成通用的,这样我就可以将它应用到我希望的任何课程中。我尝试使用< T>将myTypeDescriptionProvider类更改为泛型,但这似乎根本不起作用(更不用说
,CustomTypeDescriptor类仍然硬编码到特定的类对象。


这仍然是推荐的管理方式吗?如果是这样,有人可以提供关于如何使类足够通用以应用于任何对象的任何建议吗?

解决方案



我正在尝试将DGV列绑定到第二级属性class(即Client.Name)。


 


我看过这里描述的Linda Liu的方法:http://blogs.msdn的.com / b / msdnts /存档/ 2007/01/19 /如何对绑定-A-datagridview的列到一个第二电平属性对的一数据-source.aspx


这个看起来像它会起作用,但是我想把它变成通用的,这样我就可以将它应用到我想要的任何类中。我尝试将myTypeDescriptionProvider类更改为泛型使用< T>,但这似乎根本不起作用(更不用说
,CustomTypeDescriptor类仍然硬编码到特定的类对象。


是这还是推荐的管理方式吗?如果是这样,有人可以提供任何关于如何使类足够通用以应用于任何对象的建议吗?




Hi ObsidianPhoenix,


欢迎来到MSDN论坛。


并非所有类型都可用于绑定到DataGridView:


DataGridView类支持标准的Windows Forms数据绑定模型。这意味着数据源可以是实现以下接口之一的任何类型:


IList接口,包括一维数组。

IListSource接口,例如DataTable和DataSet类。

IBindingList接口,例如BindingList(T)类。

IBindingListView接口,例如BindingSource类。


Hi,

I'm attempting to bind a DGV column to a second level property on a class (i.e. Client.Name).

 

I've looked at Linda Liu's methods described here:http://blogs.msdn.com/b/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx

This looks like it would work, however I'd like to make it generic so that I could apply it to any class I wished. I tried changing the myTypeDescriptionProvider class to a generic using <T>, but this didnt appear to work at all (not to mention that the CustomTypeDescriptor class is still hard-coded to a particular class object.

Is this still the recommended way of managing this? If so, can someone offer any advice on how to make the classes generic enough to be applied to any object?

解决方案

Hi,

I'm attempting to bind a DGV column to a second level property on a class (i.e. Client.Name).

 

I've looked at Linda Liu's methods described here:http://blogs.msdn.com/b/msdnts/archive/2007/01/19/how-to-bind-a-datagridview-column-to-a-second-level-property-of-a-data-source.aspx

This looks like it would work, however I'd like to make it generic so that I could apply it to any class I wished. I tried changing the myTypeDescriptionProvider class to a generic using <T>, but this didnt appear to work at all (not to mention that the CustomTypeDescriptor class is still hard-coded to a particular class object.

Is this still the recommended way of managing this? If so, can someone offer any advice on how to make the classes generic enough to be applied to any object?


Hi ObsidianPhoenix,

Welcome to the MSDN Forum.

Not all the types can be used to bind to the DataGridView:

The DataGridView class supports the standard Windows Forms data-binding model. This means the data source can be of any type that implements one of the following interfaces:

The IList interface, including one-dimensional arrays.
The IListSource interface, such as the DataTable and DataSet classes.
The IBindingList interface, such as the BindingList(T) class.
The IBindingListView interface, such as the BindingSource class.


这篇关于DataGridView绑定到第二级属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆