CorrectCode 2 remove items from checkedlistbox?

How can I delete or remove items that I check from a checkedlistbox?
I added a button and tried using the code below in the button click form:

[color=Purple] If CheckedListBox1.CheckedItems.Count <> 0 Then
Dim x As Integer
Dim s As String = ""
For x = 0 To CheckedListBox1.CheckedItems.Count - 1
s = s & "" & "" & CheckedListBox1.CheckedItems(x).ToString & ControlChars.CrLf
Next x
CheckedListBox1.Items.Remove(s)


End If[/color]

But it didn't work. I borrowed and modified it from the visual basic's help section. It worked to send checked boxes to clipboard like this:

[color=Purple]If CheckedListBox1.CheckedItems.Count <> 0 Then
Dim x As Integer
Dim s As String = ""
For x = 0 To CheckedListBox1.CheckedItems.Count - 1
s = s & CheckedListBox1.CheckedItems(x).ToString & ControlChars.CrLf
Next x
My.Computer.Clipboard.SetText(s)



End If[/color]

So that is why I thought it would work to help remove the unwanted items in the list! Any help will be appreciated!!!
This is my very first program but I can tell I enjoy the vb language! I just hope I can catch on!!
Jennifer

Comments

  • : How can I delete or remove items that I check from a checkedlistbox?
    : I added a button and tried using the code below in the button click
    : form:

    If using vb6, need to examine the [Selected] property
    [its not intuitive and had to think on this one!]

    Private Sub Command1_Click()
    With Me.List1
    .AddItem "a"
    .AddItem "b"
    .AddItem "c"
    .AddItem "1"
    .AddItem "2"
    .AddItem "3"
    End With
    End Sub

    Private Sub Command2_Click()
    Dim i As Integer

    'START AT LAST LIST ITEM AND WORK TO FIRST
    For i = Me.List1.ListCount - 1 To 0 Step -1
    'IS SELECTED?
    If Me.List1.Selected(i) = True Then
    'REMOVE SELECTED ITEMS
    Me.List1.RemoveItem (i)
    End If
    Next
    End Sub
  • Hi,

    AS we know that CheckedListBox consists of Items in it with Check Box. Can we retrive those CheckBoxes for each item so that we can change properties of each of the CheckBoxItem in it.

    I want to apply colur theme to the check box in the CheckedListBox and I am unable access the checkBoxes.

    As I retrive items of CheckedListBox, I get the Item as object and not as Control(CheckBox).


    Please help me to understand how to access the item CheckBox controls.

    Thanks,
    Chetan Deshmukh
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories