Results 1 to 4 of 4

Thread: Easy ListBox question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Hi,
    I have a form with a ListBox (with Style = 1-Checkbox) and a command button. At any time the listbox contains between 5 and 15 itmes that user can check (select). I want the command button to be enabled ONLY if 1 or more items in the listbox are CHECKED (not just highlighted). And as soon as user deselects ALL items I want to disable the command button.

    Your help is appreciated.
    Thanks

    Tomexx.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Try this:
    Code:
    Private Sub List1_ItemCheck(Item As Integer)
        static selcount As Integer
        selcount = selcount - (List1.Selected(Item)) * 2 - 1
        Command1.Enabled = selcount
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    Thanks Kedaman, It works great!
    Can you explain how it works, I'm puzzled by the code.
    Specially those two lines:

    selcount = selcount - (List1.Selected(Item)) * 2 - 1
    Command1.Enabled = selcount
    Thanks

    Tomexx.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The selected property returns true if the item specified by index, is selected. And of course false if not.
    Well in vb
    false = 0 and
    true = -1
    The selcount i declared static there should count the amount of items selected, if the item that was clicked is set false then you need to decrease selcount, on the other hand true should increase selcount. To get -1 and +1 instead of 0 and -1 you multiply by 2 and substract 1.
    Enable is a boolean property and should be set to true if selcount is non-0 that means the implicit convertion used is cbool().
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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