Results 1 to 24 of 24

Thread: Here's a stupid question!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244

    Here's a stupid question!

    I have a checked list box that has 10 values in it.

    I want to create a button that selects (or deselects) all of them at once. I am assuming I have to do a:

    For Each strItems in ListBox1.Items

    Next

    But what is the syntax to check a box?


    Thanks in advance,

    Jim

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    Resolved but I am sure there is an easier way than this...

    VB Code:
    1. Dim intCount As Integer
    2.         Dim x As Integer = 0
    3.         For intCount = 0 To lbDriversVer2.Items.Count.ToString - 1
    4.             lbDriversVer2.SetItemChecked(x, True)
    5.             x = x + 1
    6.         Next

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Hey man, look at your code. It can be done in this way, i guess better syntax
    VB Code:
    1. Dim intCount As Integer
    2. For intCount = 0 To lbDriversVer2.Items.Count- 1
    3.             lbDriversVer2.SetItemChecked(intCount, True)
    4. Next
    There are some technical problems in your code, if already dont know them i will tell you.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by jlegan
    VB Code:
    1. For intCount = 0 To lbDriversVer2.Items.Count.ToString - 1
    This may work but , it doesn't make sense . Why did you convert count property to string ?. Just wonder !

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    That was one of technical problems i was talking about
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Lunatic3
    That was one of technical problems i was talking about
    lol ..One of them ? I can't see anything else wrong ! right ?

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Isn't defining:
    Dim x As Integer = 0
    and using that a poor technique?
    Last edited by Lunatic3; May 20th, 2003 at 03:59 PM.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    Ok, follow-up question:

    This works
    VB Code:
    1. Dim intCount As Integer
    2. For intCount = 0 To lbDriversVer2.Items.Count- 1
    3.             lbDriversVer2.SetItemChecked(intCount, True)
    4. Next

    Now if I add the funtionality to make to check or uncheck all of them when I click on it it checks all of them however when I uncheck it nothing happens (it doesn't seem to process it again and take the Else route):
    VB Code:
    1. Private Sub chkVer2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkVer2.CheckedChanged
    2.  
    3.         Dim intCount As Integer
    4.         If chkVer2.CheckState.Checked Then
    5.  
    6.             For intCount = 0 To lbDriversVer2.Items.Count - 1
    7.                 lbDriversVer2.SetItemChecked(intCount, True)
    8.             Next
    9.  
    10.         Else
    11.  
    12.             For intCount = 0 To lbDriversVer2.Items.Count - 1
    13.                 lbDriversVer2.SetItemChecked(intCount, False)
    14.             Next
    15.         End If
    16.     End Sub

    Any thoughts as to why?
    Last edited by jlegan; May 20th, 2003 at 04:10 PM.

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Lunatic3
    Isnt defining:
    Dim x As Integer = 0
    and using that a poor technique.
    No way , you kidding , why it's poor tech ?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    LOL I sure am glad that everyone here encourages learning seeing as I have just finished writting my first application from scratch and I have to deal with ppl making fun of the syntax I used when trying to figure something out.

  11. #11
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    No way , you kidding , why it's poor tech ?
    Are you making fun of me?
    That Dim... per se is not a poor technique, but in his code it was not needed at all. (this is for jlegan)
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    Lun,

    In proper technique and form do you know the answer to about 3 posts ago about toggling it back and forth?

  13. #13
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    doesn't seem to process it again and take the Else route):
    So check your If statment, it may always return true.
    If chkVer2 is a checkbox then you may use:
    VB Code:
    1. Dim intCount As Integer
    2. For intCount = 0 To lbDriversVer2.Items.Count- 1
    3.             lbDriversVer2.SetItemChecked(intCount, chkVer2.Checked)
    4. Next
    You dont need any if Statment, and that code goes in cchkVer2_CheckedChanged method.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  14. #14
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Lunatic3
    Are you making fun of me?
    That Dim... per se is not a poor technique, but in his code it was not needed at all. (this is for jlegan)
    lol ...Sorry dude . It's not that but I's wonderin why it's bad tech as you said . In C# , you you have to initialize the variable before you use it (well , it's highly recommended I believe) . So not a big deal .

  15. #15
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Pirate! for Gods sake tell me if he needed to use X in his original code or not
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  16. #16
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Lunatic3
    Pirate! for Gods sake tell me if he needed to use X in his original code or not
    What's X you are talking about ? interger = 0 ??

  17. #17
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Yes, and it subsequent use in the code above
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  18. #18
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by jlegan
    Resolved but I am sure there is an easier way than this...

    VB Code:
    1. Dim intCount As Integer
    2.         Dim x As Integer = 0
    3.         For intCount = 0 To lbDriversVer2.Items.Count.ToString - 1
    4.             lbDriversVer2.SetItemChecked(x, True)
    5.             x = x + 1
    6.         Next
    Uh..Well , yes , absolutely no need to use it . right Lunatic3

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    Can someone please just tell me why this will check all of the boxes in the checked list box when checked but will not uncheck them when it gets unchecked?

    VB Code:
    1. Private Sub chkVer2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkVer2.CheckedChanged
    2.  
    3.         Dim intCount As Integer
    4.         If chkVer2.CheckState.Checked Then
    5.  
    6.             For intCount = 0 To lbDriversVer2.Items.Count - 1
    7.                 lbDriversVer2.SetItemChecked(intCount, True)
    8.             Next
    9.  
    10.         Else
    11.  
    12.             For intCount = 0 To lbDriversVer2.Items.Count - 1
    13.                 lbDriversVer2.SetItemChecked(intCount, False)
    14.             Next
    15.         End If
    16.     End Sub

  20. #20
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    What is "chkVer2" , I couldn't figure it out !

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    chkVer2 is a single checkbox
    lbDriversVer2 is a Checked List Box

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    I also changed the Event Handler to .CheckStateChanged but that didn't make a difference either.

  23. #23
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    The code i sent you 9 posts before this was useless????

    by the way you should use:
    chkVer2.CheckState=CheckState.Checked
    Last edited by Lunatic3; May 20th, 2003 at 04:29 PM.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    Thanks lun that fixed it

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