新西兰服务器

VB.NET数据绑定怎么用


VB.NET数据绑定怎么用

发布时间:2021-12-01 17:13:12 来源:高防服务器网 阅读:54 作者:小新 栏目:编程语言

这篇文章主要介绍VB.NET数据绑定怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

VB.NET数据绑定能应用于控件的任何属性。我看到过很多人提到能够绑定文本框的背景颜色到数据项,举个例子,超期的帐号的背景色显示红色。但是如果你试图使用数据集或者数据表实现该功能,将会遇到问题。数据行只能保持受到限制的数据类型,并且不支持Color类型。如果你不能把颜色存储在VB.NET数据绑定颜色呢?

有些途径可以解决这个问题,但是最简单的是用绑定到自定义VB.NET数据绑定到数据表。自定义业务对象的属性可能是Color型的,这样的属性能绑定到控件的BackColor属性。

为了演示,我定义了下面的自定义事务对象:

Public Class Account   Dim m_nAccountID As Integer  Dim m_sCustomerName As String  Dim m_dblBalance As Double   Public Sub New(ByVal nAccountID As Integer, ByVal sCustomerName As   String, _ByVal dblBalance As Double)  Me.AccountID = nAccountID Me.CustomerName = sCustomerName Me.Balance = dblBalance End Sub   Public Property AccountID() As Integer  Get  Return m_nAccountID  End Get  Set(ByVal Value As Integer)  m_nAccountID = Value End Set  End Property   Public Property CustomerName() As String  Get  Return m_sCustomerName  End Get  Set(ByVal Value As String)  m_sCustomerName = Value End Set  End Property   Public Property Balance() As Double  Get  Return m_dblBalance  End Get  Set(ByVal Value As Double)  m_dblBalance = Value End Set  End Property   Public ReadOnly Property BackColor() As Color  Get  If m_dblBalance < 0 Then  Return Color.Salmon  Else  Return SystemColors.Window  End If  End Get  End Property  End Class

注意只读的BackColor属性从Balance属性中得到值,并且为负平衡(negative balance)暴露了一个不同的颜色。该类的其它元素很直接。

以上是“VB.NET数据绑定怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注高防服务器网行业资讯频道!

[微信提示:高防服务器能助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

[图文来源于网络,不代表本站立场,如有侵权,请联系高防服务器网删除]
[