Results 1 to 26 of 26

Thread: [RESOLVED] check box to remove items from list?

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Re: check box to remove items from list?

    Quote Originally Posted by Mitch_s_s
    could you not use checkbox on change
    then put
    VB Code:
    1. if checkbox.value = true then
    2.   label.text = "Whatever you want to display here"
    3. end if

    or am i missing the point?
    That is similar to the idea i have, however i want it so when the checkbox.value = true and the checkbox is for a certain word in the list, and the word comes up as the label.text, it randomizes again. but i cant get it to work.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Re: check box to remove items from list?

    im not really sure what i should do.
    VB Code:
    1. if checkbox.value = true ??????????
    2. if label1.text = "xxxxx" then
    3. Dim i As Integer
    4.    
    5.     Randomize
    6.     i = Rnd(List1.ListCount) * List1.ListCount
    7.     Label4.Caption = List1.List(i)
    8. end if
    im not sure if that is how i should do it. im not sure what i need to put in the area with the "????" or if this is the best way of doing this, or even if this way is possible.
    i also just tried this but it didnt work.
    VB Code:
    1. If chkboxuf1.Value = True Then
    2.     With List1
    3.         .RemoveItem "AAA"
    4.         End With
    5.         End If

    I have the lists load with the form, like this
    VB Code:
    1. Private Sub Form_Load()
    2. With List1
    3.     .AddItem "AAA"
    4.     .AddItem "BBB"
    5.     .AddItem "CCC"
    6.     .AddItem "DDD"
    7.    
    8.     End With
    Last edited by stevevb6; Jan 31st, 2007 at 12:07 PM.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: check box to remove items from list?

    You can't remove an item from a listview based solely on it's value. You need to know the index of the value. The following does that. I go through the list backward in case there is more than one entry with the same value.

    VB Code:
    1. Dim lngIndex As Long
    2.    
    3.     For lngIndex = List1.ListCount - 1 To 0 Step -1
    4.         If List1.List(lngIndex) = "AAA" Then
    5.             List1.RemoveItem lngIndex
    6.         End If
    7.     Next

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Re: check box to remove items from list?

    Do i just replace what i have with that?

    VB Code:
    1. If chkboxuf1.Value = True Then
    2.     Dim lngIndex As Long
    3.    
    4.     For lngIndex = List1.ListCount - 1 To 0 Step -1
    5.         If List1.List(lngIndex) = "AAA" Then
    6.             List1.RemoveItem lngIndex
    7.         End If
    8.     Next

  5. #5

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Re: check box to remove items from list?

    it isnt going to work for what i want it for. that code removes the item from the list, and when the checkbox is unchecked, it does not come back. i need something to make the program randomize again when the label1.caption = the caption of the check box, only when the checkbox.value = true.
    Last edited by stevevb6; Jan 31st, 2007 at 01:11 PM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Re: check box to remove items from list?

    how can i add an item to the list by clicking the check box,
    like this?
    VB Code:
    1. If chkboxuf1.Value = True Then
    2.       Dim lngIndex As Long
    3.     End If
    4.     For lngIndex = List1.ListCount - 1 To 0 Step -1
    5.         If List1.List(lngIndex) = "UF1" Then
    6.             List1.AddItem lngIndex
    7.                End If
    8.     Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width