Results 1 to 7 of 7

Thread: [RESOLVED] listbox cotrol array select/unselect

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    736

    Resolved [RESOLVED] listbox cotrol array select/unselect

    Hi guys

    got a real silly question i have a set of 6 listboxs in a control array, i want to set them in such a way that when i click one the others are unclicked(unhighlighted). i know i can do this with loads of ifs and end ifs but i am also sure that there is another way with like a line or so of code its just my mind is blank?

    any ideas?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: listbox cotrol array select/unselect

    I'm not sure what you mean by unclicked(unhighlighted), so I will show an example of Enabled instead - based on what you said you should be able to work it out from there.
    Code:
    Private Sub lstMyArray_Click(Index As Integer)
    
    Dim ctlTempList As Control
      For Each ctlTempList In lstMyArray
        If ctlTempList.Index <> Index Then
          ctlTempList.Enabled = False
        End If
      Next ctlTempList
    
    End Sub

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    736

    Re: listbox cotrol array select/unselect

    Yep worked it and i was so close yet so far thanks

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    736

    Re: [RESOLVED] listbox cotrol array select/unselect

    Bah almost works any ideas

    Code:
    Dim ctl As Control
    For Each ctl In LstOtput
    If Not ctl.Index <> Index Then
    ctl.ListIndex = "-1"
    End If
    Next ctl
    basically when you click a listbox the selected line turns blue, if so with numnerous listboxs clicked one after the other they all have a selected line visible in blue. the code you supplied almost works as above but on clicking a listbox it unselects all of them inclueding the one clicked then if you click it once more it selects the list clicked.

    the effect i am after is i suppose like a set of radio buttons in a frame when one is selected the others are unselected.

    Attached from as example
    Attached Files Attached Files

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    736

    Re: [RESOLVED] listbox cotrol array select/unselect

    Jeez i am such a noob have it firing on click this needed to happen on got focus

    thanks again

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [RESOLVED] listbox cotrol array select/unselect

    Ah yes, I see what you meant now.

    To make it work, simply use the _GotFocus event instead of _Click (edit: as you found out already!)


    Note that you aren't setting the ListIndex properly.. it is a Numeric property, so you should not be passing it a String (ie: it should be ctl.ListIndex = -1 )

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    736

    Re: [RESOLVED] listbox cotrol array select/unselect

    Fixed thanks again

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