如何将数据加载到 ArrayList 中
来源:互联网 发布:Linux的loop 编辑:程序博客网 时间:2024/05/16 00:19
ArrayList是一个集合,动态数组,可以放任何对象Object。动态的增加和减少元素,实现了ICollection和IList接口
灵活的设置数组的大小。
Imports System.Collections
Public Class FrmSelFileSetionClassClass FrmSelFileSetionClass FrmSelFileSetion
Private Class FileSetionClassClass FileSetionClass FileSetion
Private myFNameEN As String
Private myFNameCN As String
Public Sub New()Sub New()Sub New()Sub New(ByVal FNameEN As String, ByVal FNameCN As String)
myFNameEN = FNameEN
myFNameCN = FNameCN
End Sub
Public ReadOnly Property FNameEN()Property FNameEN()Property FNameEN()Property FNameEN() As String
Get
Return myFNameEN
End Get
End Property
Public ReadOnly Property FNameCN()Property FNameCN()Property FNameCN()Property FNameCN() As String
Get
Return myFNameCN
End Get
End Property
End Class
Dim FList As New ArrayList()
Private Sub FrmSelFileSetion_Load()Sub FrmSelFileSetion_Load()Sub FrmSelFileSetion_Load()Sub FrmSelFileSetion_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FList.Add(New FileSetion("ItmeNo", "货号"))
FList.Add(New FileSetion("ItmeSize", "尺寸"))
FList.Add(New FileSetion("UnitPrice", "价格"))
FList.Add(New FileSetion("ProductWeight", "产品重量"))
FList.Add(New FileSetion("DimensionOutL,DimensionOutW,DimensionOutH", "外箱尺寸"))
FList.Add(New FileSetion("DimensionOutGW", "外箱重量"))
FList.Add(New FileSetion("CasePackOut", "外箱装箱量"))
FList.Add(New FileSetion("ShipQTY,ShipCTN", "40尺柜装箱量"))
ListBox1.DataSource = FList
ListBox1.ValueMember = "FNameEN"
ListBox1.DisplayMember = "FNameCN"
End Sub
Private Sub ListBox1_MouseDown()Sub ListBox1_MouseDown()Sub ListBox1_MouseDown()Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
If Me.ListBox1.SelectedIndex <> -1 Then
Me.ListBox1.DoDragDrop(Me.ListBox1.Text & "|@|" & Me.ListBox1.SelectedValue.ToString, DragDropEffects.Copy)
End If
End Sub
Private Sub TextBoxS_DragDrop()Sub TextBoxS_DragDrop()Sub TextBoxS_DragDrop()Sub TextBoxS_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop, TextBox2.DragDrop, TextBox3.DragDrop, TextBox4.DragDrop
If e.Data.GetDataPresent(DataFormats.Text) Then
Dim SelData() As String
SelData = Split(e.Data.GetData(DataFormats.Text), "|@|")
CType(sender, TextBox).Text = SelData(0)
CType(sender, TextBox).Tag = SelData(1)
End If
End Sub
Private Sub TextBoxS_DragEnter()Sub TextBoxS_DragEnter()Sub TextBoxS_DragEnter()Sub TextBoxS_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter, TextBox2.DragEnter, TextBox3.DragEnter, TextBox4.DragEnter
e.Effect = DragDropEffects.Copy
End Sub
Private Sub Button1_Click()Sub Button1_Click()Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("文本:" & TextBox1.Text & vbCrLf & "隐藏内容:" & TextBox1.Tag.ToString, , "你选择的内容")
End Sub
End Class
Public Class FrmSelFileSetionClassClass FrmSelFileSetionClass FrmSelFileSetion
Private Class FileSetionClassClass FileSetionClass FileSetion
Private myFNameEN As String
Private myFNameCN As String
Public Sub New()Sub New()Sub New()Sub New(ByVal FNameEN As String, ByVal FNameCN As String)
myFNameEN = FNameEN
myFNameCN = FNameCN
End Sub
Public ReadOnly Property FNameEN()Property FNameEN()Property FNameEN()Property FNameEN() As String
Get
Return myFNameEN
End Get
End Property
Public ReadOnly Property FNameCN()Property FNameCN()Property FNameCN()Property FNameCN() As String
Get
Return myFNameCN
End Get
End Property
End Class
Dim FList As New ArrayList()
Private Sub FrmSelFileSetion_Load()Sub FrmSelFileSetion_Load()Sub FrmSelFileSetion_Load()Sub FrmSelFileSetion_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FList.Add(New FileSetion("ItmeNo", "货号"))
FList.Add(New FileSetion("ItmeSize", "尺寸"))
FList.Add(New FileSetion("UnitPrice", "价格"))
FList.Add(New FileSetion("ProductWeight", "产品重量"))
FList.Add(New FileSetion("DimensionOutL,DimensionOutW,DimensionOutH", "外箱尺寸"))
FList.Add(New FileSetion("DimensionOutGW", "外箱重量"))
FList.Add(New FileSetion("CasePackOut", "外箱装箱量"))
FList.Add(New FileSetion("ShipQTY,ShipCTN", "40尺柜装箱量"))
ListBox1.DataSource = FList
ListBox1.ValueMember = "FNameEN"
ListBox1.DisplayMember = "FNameCN"
End Sub
Private Sub ListBox1_MouseDown()Sub ListBox1_MouseDown()Sub ListBox1_MouseDown()Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
If Me.ListBox1.SelectedIndex <> -1 Then
Me.ListBox1.DoDragDrop(Me.ListBox1.Text & "|@|" & Me.ListBox1.SelectedValue.ToString, DragDropEffects.Copy)
End If
End Sub
Private Sub TextBoxS_DragDrop()Sub TextBoxS_DragDrop()Sub TextBoxS_DragDrop()Sub TextBoxS_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop, TextBox2.DragDrop, TextBox3.DragDrop, TextBox4.DragDrop
If e.Data.GetDataPresent(DataFormats.Text) Then
Dim SelData() As String
SelData = Split(e.Data.GetData(DataFormats.Text), "|@|")
CType(sender, TextBox).Text = SelData(0)
CType(sender, TextBox).Tag = SelData(1)
End If
End Sub
Private Sub TextBoxS_DragEnter()Sub TextBoxS_DragEnter()Sub TextBoxS_DragEnter()Sub TextBoxS_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter, TextBox2.DragEnter, TextBox3.DragEnter, TextBox4.DragEnter
e.Effect = DragDropEffects.Copy
End Sub
Private Sub Button1_Click()Sub Button1_Click()Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("文本:" & TextBox1.Text & vbCrLf & "隐藏内容:" & TextBox1.Tag.ToString, , "你选择的内容")
End Sub
End Class
ArrayList的几个常用的方法:
Count属性是目前ArrayList包含的元素的数量,这个属性是只读的。
Capacity属性是目前ArrayList能够包含的最大数量,可以手动的设置这个属性,但是当设置为小于Count值的时候会引发一个异常。
Add方法用于添加一个元素到当前列表的末尾
AddRange方法用于添加一批元素到当前列表的末尾
Remove方法用于删除一个元素,通过元素本身的引用来删除
RemoveAt方法用于删除一个元素,通过索引值来删除
RemoveRange用于删除一批元素,通过指定开始的索引和删除的数量来删除
Insert用于添加一个元素到指定位置,列表后面的元素依次往后移动
InsertRange用于从指定位置开始添加一批元素,列表后面的元素依次往后移动
Clear方法用于清除现有所有的元素
Contains方法用来查找某个对象在不在列表之中
TrimSize这个方法用于将ArrayList固定到实际元素的大小,当动态数组元素确定不在添加的时候,可以调用这个方法来释放空余的内存。
ToArray这个方法把ArrayList的元素Copy到一个新的数组中。
- 如何将数据加载到 ArrayList 中
- 如何将需要处理的数据加载到项目中Scala项目中
- 如何将一个文本文件中的数据加载到oracle数据库中
- winform如何实现将数据库数据加载到树上
- 将数据对象加载到下拉列表中
- 164,将.plist文件中的数据加载到程序中
- 14web启动将数据加载到内存中
- 将json中的数据加载到table和ul中
- 如何将自己的地图加载到google地图中
- 如何将指定文件夹下的所有报表文件循环加载到GridView空间中 并且打开某条数据
- 将ArrayList中的元素深copy到另一个ArrayList中
- 将数据库中的数据读入到ArrayList中,并在页面上显示
- 随机的将1-100之间的数据添加到 ArrayList数组中
- 如何将ORACLE9i中的数据导出到ORACLE8i中?
- 如何将EXCEL数据导入到SQL数据库中来
- 如何将DataGrid中的数据导出到Excel文件中
- Asp.Net中如何将数据导出到excel
- 如何将DataGrid中的数据导出到Excel文件中
- Hibernate3官方教程-第1章-第2部分
- 常用 SQL 语句大全
- 提高点击率
- js test
- ASP.NET 2.0 中FileUpload上传控件的使用
- 如何将数据加载到 ArrayList 中
- ASP.NET 2.0 分页技术之使用PagedDataSource篇
- 《Solaris 红宝书》系列在线课程
- ASP.NET 2.0 分页技术之使用纯sql语句的双top分页篇
- 学习EXT第二天:EXT简介(二)
- 用C#编写的计算器小程序
- WEB开发中的JAVA字符编码经验总结
- SQL Server + VS2005 + 3层结构 + EXT2.0 + ajax 的 增删改 的例子
- ASP.NET 2.0 制作彩色验证码