接口和绑定... [英] Interfaces and Binding...

查看:43
本文介绍了接口和绑定...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在绑定到List(Of ISomething)时遇到问题.
我目前有一个SalesOrder类,其中有一个
Property OrderDetails As List(Of IOrderDetail) Implements IOrder.OrderDetails.
问题是,当我将此列表绑定到DataGridView时,我只会看到Interface中定义的Properties列.这是预期的行为,但是我想查看我的SalesOrderDetail的属性,而不是IOrderDetail.
我尝试过将CTypeing List(Of IOrderDetail)更改为List(Of SalesOrderDetail),但是似乎不允许使用CTyping List(Of T). List(Of IOrderDetail)不能转换为List(Of SalesOrderDetail),尽管两者都是IOrderDetail并且List(Of IOrderDetail)实际上包含SalesOrderDetails ...

我遇到的另一个问题是我的OrderDetail具有Property Product As IProduct Implements IOrderDetail.Product.我已经将SalesOrder绑定到DataGridView,但是无法将类绑定到DataGridViewColumn(产品属性),所以我希望DataGridViewColumn改为显示产品的Name属性...(所以我实际上是在绑定属性财产).

感谢您的任何帮助:)

I have a problem with binding to List(Of ISomething).
I currently have a SalesOrder Class that has a
Property OrderDetails As List(Of IOrderDetail) Implements IOrder.OrderDetails.
The problem is that when I bind this list to a DataGridView I only get to see the columns of Properties defined in the Interface. That''s expected behaviour, but I would like to see the properties of my SalesOrderDetail, not the IOrderDetail.
I have tried CTyping the List(Of IOrderDetail) to List(Of SalesOrderDetail), but it seems that CTyping List(Of T) is not allowed. List(Of IOrderDetail) cannot be converted to List(Of SalesOrderDetail), though both are IOrderDetail and the List(Of IOrderDetail) actually contains SalesOrderDetails...

Another problem I have is that my OrderDetail has a Property Product As IProduct Implements IOrderDetail.Product. I have bound my SalesOrder to a DataGridView, but I cannot bind a Class to a DataGridViewColumn (the Product Property), so I want the DataGridViewColumn to show the Name Property of the Product instead... (So I would actually be binding a Property of a Property).

Any help is appreciated :)

推荐答案

关于您的第一个问题:您不应该尝试这样做.如果您传递的具体类没有所需的属性,则会出现异常.我建议您为接口创建自己的控件,然后将其专用于要使用的具体类.

关于第二个问题,您可以设置一个对象数据源并将其绑定到该数据源,或者可以查看
With respect to your first question: you shouldn''t try to do this. If you pass in a concrete class that doesn''t have the required properties you''ll get an exception. I suggest you create your own control for the Interface, then specialize it for the concrete class you want to use.

With respect to your second question, you can set up an object data source and bind to that or you can take a look at http://msdn.microsoft.com/en-us/library/y0wfd4yz.aspx[^]. Binding an individual object to a list control doesn''t make much sense however.


Hope this helps!


这篇关于接口和绑定...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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