用VB或VBA语言,做两个多列(2列)列表框之间数据的相互转移,语言怎么写?
我做的程序由第一列表(单选)向第二个列表框转移时,第二个列框的第一行可以出现我选中的第一列表框的内容,但到第二行时,第二列框只能显示第一列能依次显示第二列除了第一个其他都...
我做的程序由第一列表(单选)向第二个列表框转移时,第二个列框的第一行可以出现我选中的第一列表框的内容,但到第二行时,第二列框只能显示第一列能依次显示第二列除了第一个其他都是空的,
Private Sub CommandButton1_Click()
Dim j%
With ListBox2
.ColumnCount = 2
.ColumnWidths = "55,20"
.BoundColumn = 0
.ColumnHeads = True
For j = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(j) Then
.AddItem ListBox1.List(j)
.List(j, 1) = ListBox1.List(j, 1)
ListBox1.RemoveItem ListBox1.ListIndex
End If
Next
End With
End Sub 展开
Private Sub CommandButton1_Click()
Dim j%
With ListBox2
.ColumnCount = 2
.ColumnWidths = "55,20"
.BoundColumn = 0
.ColumnHeads = True
For j = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(j) Then
.AddItem ListBox1.List(j)
.List(j, 1) = ListBox1.List(j, 1)
ListBox1.RemoveItem ListBox1.ListIndex
End If
Next
End With
End Sub 展开
2个回答
展开全部
给你个实例吧,到参考的网址去下载。 从里面摘了2个过程
' 移动一条
Private Sub MoveOneItem(SrcList As ListBox, DesList As ListBox)
If SrcList.ListCount > 0 Then
If SrcList.ListIndex < 0 Then
SrcList.ListIndex = 0
End If
DesList.AddItem SrcList.List(SrcList.ListIndex)
DesList.ItemData(DesList.NewIndex) = SrcList.ItemData(SrcList.ListIndex)
ListDelItem SrcList, SrcList.ListIndex
End If
End Sub
' 全体移动
Private Sub MoveAllItem(SrcList As ListBox, DesList As ListBox)
Dim i As Integer
i = 0
Do While i < SrcList.ListCount
DesList.AddItem SrcList.List(i)
DesList.ItemData(DesList.NewIndex) = SrcList.ItemData(i)
i = i + 1
Loop
SrcList.Clear
End Sub
' 移动一条
Private Sub MoveOneItem(SrcList As ListBox, DesList As ListBox)
If SrcList.ListCount > 0 Then
If SrcList.ListIndex < 0 Then
SrcList.ListIndex = 0
End If
DesList.AddItem SrcList.List(SrcList.ListIndex)
DesList.ItemData(DesList.NewIndex) = SrcList.ItemData(SrcList.ListIndex)
ListDelItem SrcList, SrcList.ListIndex
End If
End Sub
' 全体移动
Private Sub MoveAllItem(SrcList As ListBox, DesList As ListBox)
Dim i As Integer
i = 0
Do While i < SrcList.ListCount
DesList.AddItem SrcList.List(i)
DesList.ItemData(DesList.NewIndex) = SrcList.ItemData(i)
i = i + 1
Loop
SrcList.Clear
End Sub
参考资料: http://www.codefans.net/soft/8326.shtml
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询