VB.NET CheckedListBox1操作

 If CheckedListBox1.Items.Count <> 0 Then'全部选中
            For u As Integer = 0 To CheckedListBox1.Items.Count - 1


                CheckedListBox1.SetItemChecked(u, True)

 

 

 

            Next

 

 

 

 

If CheckedListBox1.Items.Count <> 0 Then '反选
            For u As Integer = 0 To CheckedListBox1.Items.Count - 1


                CheckedListBox1.SetItemChecked(u, Not (CheckedListBox1.GetItemChecked(u)))  


            Next
        Else
            MsgBox("反向选中遇到错误:列表数据为空,本次操作无效。", MsgBoxStyle.Critical)

        End If

 

 If CheckedListBox1.Items.Count <> 0 Then'清空数据
            CheckedListBox1.Items.Clear()
        Else
            MsgBox("清空数据遇到错误:列表数据为空,本次操作无效。", MsgBoxStyle.Critical)

        End If

 

 

 Dim indexes As CheckedListBox.CheckedIndexCollection = Me.CheckedListBox1.CheckedIndices'删除选中项
        If indexes.Count > 0 Then
            For Each index In indexes
                Me.CheckedListBox1.Items.RemoveAt(indexes(0))
            Next
            Label1.Text = CheckedListBox1.Items.Count
        Else
            MsgBox("删除数据遇到错误:列表数据为空或在列表中至少勾选一项数据。", MsgBoxStyle.Critical)

        End If

 

 

If  CheckedListBox1.Items.Count > 5 Then '保留前5条数据,其余全部删除
            For i = 5 To CheckedListBox1.Items.Count - 1
                CheckedListBox1.Items.RemoveAt(CheckedListBox1.Items.Count - 5)

            Next

       End if

 

If InStr(CheckedListBox1.SelectedItem, "(NEW)") > 0 Then '修改选中项内容
            Dim dhsyd = Replace(CheckedListBox1.SelectedItem, "(NEW)", "")
            CheckedListBox1.Items.Insert(CheckedListBox1.SelectedIndex, dhsyd)
            CheckedListBox1.Items.RemoveAt(CheckedListBox1.SelectedIndex)
            CheckedListBox1.SelectedIndex = Label1.Text
        End If

你可能感兴趣的:(VB.Net,.net)