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

How to use VB.NET data binding

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

Share

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

This article mainly introduces how to use VB. NET data binding, the text is very detailed, has a certain reference value, interested friends must read!

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. What if you can't store colors in VB. NET DataBinding Colors?

There are several ways to solve this problem, but the simplest is to bind to custom VB. NET 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. Other elements of this class are straightforward.

The above is "VB. NET data binding how to use" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

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