前端之家收集整理的这篇文章主要介绍了
VB.NET两个LISTBOX进行交换数据,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnRightMove.Click,LstAll.DoubleClick '右移数据
If LstAll.SelectedItems.Count > 0 Then
If LstPart.Items.Contains(LstAll.SelectedItem) Then Exit Sub
LstPart.Items.Add(LstAll.SelectedItem)
LstAll.Items.Remove(LstAll.SelectedItem)
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnLeftMove.Click,LstPart.DoubleClick '左移数据
If LstPart.SelectedItems.Count > 0 Then
If LstAll.Items.Contains(LstPart.SelectedItem) Then Exit Sub
LstAll.Items.Add(LstPart.SelectedItem)
LstPart.Items.Remove(LstPart.SelectedItem)
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnRightAll.Click '右移全部数据
If LstAll.Items.Count < 1 Then Exit Sub
' Dim LstItem As Object
'For Each LstItem In LstAll.Items
' If Not LstPart.Items.Contains(LstItem) Then
' LstPart.Items.Add(LstItem)
' End If
'Next
'Dim i As Integer,nCount As Integer
'nCount = LstAll.Items.Count
''For i = 1 To nCount
'' LstAll.Items.AddRange(LstAll.Items)
''Next
' LstAll.Items.Remov
LstPart.Items.AddRange(LstAll.Items)
LstAll.Items.Clear()
End Sub
Private Sub BtnLeftAll_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnLeftAll.Click '左移全部数据
If LstPart.Items.Count < 1 Then Exit Sub
'Dim LstItem As Object
'For Each LstItem In LstPart.SelectedItems
' If Not LstAll.Items.Contains(LstItem) Then
' LstAll.Items.Add(LstItem)
' End If
' 'LstPart.Items.Remove(LstItem)
' 'Me.ListBox2.Items.AddRange(Me.ListBox1.Items)
' 'Me.ListBox1.Items.Clear()
'Next
'Dim i As Integer,nCount As Integer
'nCount = LstPart.SelectedItems.Count
'For i = 1 To nCount
' LstPart.Items.Remove(LstPart.SelectedItem)
'Next
LstAll.Items.AddRange(LstPart.Items)
LstPart.Items.Clear()
End Sub