vb.net Checklistbox 如何把选中的值移动到另个一checklistbox里面并且在原有的里面删除

 

如何把checklistbox里面的多个值选中并且移动到另个checklistbox框去,然后把选中的值在原有的checklistbox框里面删除

具体代码如下:

下面的代码是在添加和删除button的click事件里面写的,大家可以根据自己的需要写到你要用到的地方。

本人测试OK

说明点,代码离得循环要从大到小

  Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        Try
            Dim j As Integer
            Dim s As String   
            For j = clbox1.Items.Count - 1 To 0 Step -1
                s = clbox1.Items.Count
                If clbox1.GetItemChecked(j) = True Then
                    clbox2.Items.Add(clbox1.Items(j).ToString)
                    clbox1.Items.RemoveAt(j)
                End If
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
       
        
    End Sub

    Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
        Try
            Dim j As Integer
            For j = clbox2.Items.Count - 1 To 0 Step -1
                If clbox2.GetItemChecked(j) = True Then
                    clbox1.Items.Add(clbox2.Items(j).ToString)
                    clbox2.Items.RemoveAt(j)
                End If
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
       
    End Sub


 

 

你可能感兴趣的:(VB.NET)