Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

  • dokken2dokken2 Posts: 532Member
    : 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
  • chetandeshmukhchetandeshmukh Posts: 1Member
    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.