VB.NET Account对象简介

开发 后端
本文介绍三个文本框都用于保持当前VB.NET Account对象的数据。它们分别叫txtAccountID、txtCustomerName和 txtBalance.显示Load的按钮叫btnLoad,用于载入帐号集合。

VB.NET有很多值得学习的地方,这里我们主要介绍VB.NET Account对象,包括介绍是Load方法的Click事件等方面。

本文介绍三个文本框都用于保持当前VB.NET Account对象的数据。它们分别叫txtAccountID、txtCustomerName和 txtBalance.显示Load的按钮叫btnLoad,用于载入帐号集合。另两个按钮在记录间导航,分别叫btnBack 和 btnForward.

帐号对象集合可以保持在ArrayList(数组列表)中,因此下面一行代码应该在窗体代码的最前面:

Dim colAccounts As ArrayList

下面是Load方法的Click事件代码。它建立了一些VB.NET Account对象并把它们放入一个集合中,接着把该集合绑定到文本框。

  1. colAccounts = New ArrayList()  
  2. colAccounts.Add(New Account(1, "ABC Company", 10))  
  3. colAccounts.Add(New Account(2, "XYZ, Inc.", -10))  
  4. colAccounts.Add(New Account(3, "MNP Limited", 0))  
  5.  
  6. txtAccountID.DataBindings.Add(New _   
  7. Binding("Text", colAccounts, "AccountID"))  
  8. txtCustomerName.DataBindings.Add(New _   
  9. Binding("Text", colAccounts, "CustomerName"))  
  10. txtBalance.DataBindings.Add(New _  
  11. Binding("Text", colAccounts, "Balance"))  
  12. txtBalance.DataBindings.Add(New _   
  13. Binding("BackColor", colAccounts, "BackColor")) 

注意最后两行。txtBalance的Text属性绑定到一个帐号的Balance属性,并且该控件的BackColor属性绑定到帐号对象的BackColor属性。它演示了。NET框架组件绑定一个以上属性到不同数据项。

现在点击btnBack的Click事件,填入一下代码:

  1. If Me.BindingContext(colAccounts).Position > 0 Then  
  2. Me.BindingContext(colAccounts).Position -1 
  3. End If  
  4. 在btnForward的Click事件中写入以下代码:  
  5. If Me.BindingContext(colAccounts).Position < colAccounts.Count - 1 Then  
  6. Me.BindingContext(colAccounts).Position += 1  
  7. End If 

【编辑推荐】

  1. 简单描述VB.NET散列函数
  2. 详细分析VB.NET读写文本文件
  3. VB.NET GroupBox控件学习经验
  4. 概括VB.NET DomainUpDown控件
  5. VB.NET编码算法学习笔记
责任编辑:佚名 来源: IT168
相关推荐

2010-01-15 16:29:47

VB.NET对象存储

2009-10-28 17:44:31

VB.NET语言

2009-10-16 11:38:47

VB.NET使用Ali

2009-10-15 09:16:35

VB.NET重新申明数

2009-10-09 15:59:41

VB.NET对象

2009-10-30 15:37:23

VB.NET Sub创

2009-10-13 17:03:55

VB.NET面向对象

2009-11-02 16:22:16

VB.NET面向对象

2009-10-12 16:39:59

OracleTransVB.NET使用

2010-01-22 13:28:13

VB.NET对象克隆

2009-10-23 14:06:07

VB.NET类对象

2009-10-12 14:13:00

VB.NET使用局部变

2010-01-12 18:05:38

VB.NET对象

2009-10-30 11:20:54

VB.NET Proc

2009-11-02 17:54:44

VB.NET数组

2010-01-13 11:18:24

VB.NET面向对象

2010-01-21 16:17:32

VB.NET文件对象

2009-11-03 13:33:39

VB.NET对象列表

2009-10-20 17:38:20

VB.NET exce

2009-10-12 16:51:28

VB.NET使用Ora
点赞
收藏

51CTO技术栈公众号