Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Application skills of VB.NET data binding

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the VB. NET data binding application skills example analysis, with a certain reference value, interested friends can refer to, I hope you read this article after a lot of gains, the following let Xiaobian with everyone to understand.

The introduction of VB. NET programming language adds another language choice for developers. They can use this language to implement a variety of specific functions. VB. NET data binding can be applied to any property of a control. I've seen a lot of people mention being able to bind the background color of text boxes to data items, for example, the background color of expired accounts is red.

However, if you try to implement this functionality using datasets or data tables, you will encounter problems. Data rows can only hold restricted data types, and Color types are not supported. How can you bind colors if you can't store them in data?

There are ways to solve this problem, but the simplest is to bind VB. NET data to custom data objects instead of binding to data tables. Custom business object properties may be Color type, such properties can be bound to the BackColor property of the control.

To demonstrate, I defined the following custom transaction object:

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

Note that the read-only BackColor property gets its value from the Balance property and exposes a different color for negative balance. The other elements of this class are straightforward.

Thank you for reading this article carefully. I hope that Xiaobian will share the "Example Analysis of VB. NET Data Binding Application Skills". This article is helpful to everyone. At the same time, I hope that everyone will support you more. Pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report