Results 1 to 35 of 35

Thread: List Box

  1. #1

    Thread Starter
    New Member PaK4LyFe's Avatar
    Join Date
    Apr 2005
    Posts
    10

    List Box

    What is the code for double clicking a certain item in a list box. (EX: when I double click something that says "VB6" in a list box; a form pops up.)

  2. #2
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: List Box

    VB Code:
    1. Private Sub List1_DblClick()
    2.  
    3. MsgBox List1.List(List1.ListIndex)
    4.  
    5. End Sub

  3. #3

    Thread Starter
    New Member PaK4LyFe's Avatar
    Join Date
    Apr 2005
    Posts
    10

    Re: List Box

    this is only giving me if I click the list box as a whole. I meant a certain item in there...

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: List Box

    Rather than arguing given solution you should always try run it first - what Max gave you is absolutely correct: List1.List(List1.ListIndex) represents currently selected item in the list.

  5. #5
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: List Box

    VB Code:
    1. Private Sub List_Click()
    2.     MsgBox List.Text
    3. End Sub

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: List Box

    For Mr. |2eM!x (only)
    Quote Originally Posted by PaK4LyFe
    What is the code for double clicking a certain item in a list box. ...

  7. #7
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: List Box



    And also for |2eM!x

    Quote Originally Posted by Pak4LyFe
    this is only giving me if I click the list box as a whole. I meant a certain item in there...

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: List Box

    but it is
    VB Code:
    1. Msgbox List1.Text

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: List Box

    It is WHAT !?
    Guy asked for DBLCLICK ... NOT SINGLE ...

  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: List Box

    Quote Originally Posted by RhinoBull
    Rather than arguing given solution you should always try run it first - what Max gave you is absolutely correct: List1.List(List1.ListIndex) represents currently selected item in the list.
    Well, you don't have to double click the selected item for this code to run you could have double clicked an empty area in the ListBox which I think was what he referred to.

    The following code works though:
    VB Code:
    1. Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
    2.  
    3. Private Declare Function SendMessageNull _
    4.  Lib "user32.dll" Alias "SendMessageA" ( _
    5.  ByVal hwnd As Long, _
    6.  ByVal wMsg As Long, _
    7.  ByVal wParam As Long, _
    8.  ByVal lParam As Long) As Long
    9.  
    10. Private Const LB_GETITEMHEIGHT As Long = &H1A1
    11.  
    12. Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    13.     Static nTick As Long
    14.     Static nOldIndex As Long
    15.     Dim nHeight As Long
    16.     Dim nItem As Long
    17.    
    18.     If Button = vbLeftButton Then
    19.         'calculate which item we have clicked on
    20.         nHeight = SendMessageNull(List1.hwnd, LB_GETITEMHEIGHT, 0, 0) _
    21.          * Screen.TwipsPerPixelY
    22.         nItem = List1.TopIndex + (Y \ nHeight)
    23.         'check if we actually clicked on an item
    24.         If nItem < List1.ListCount Then
    25.             If GetTickCount - nTick < 300 And nItem + 1 = nOldIndex Then
    26.                 'okidoki we have double clicked an item
    27.                 MsgBox List1.List(nItem)
    28.             End If
    29.         End If
    30.         nTick = GetTickCount
    31.         nOldIndex = List1.ListIndex + 1
    32.     End If
    33. End Sub

  11. #11
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: List Box

    Quote Originally Posted by dglienna
    but it is
    VB Code:
    1. Msgbox List1.Text
    Oh. I tried it. Yeah as long as the MultiSelect isn't on.

    I always used the List(List1.ListIndex) thing.

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: List Box

    Ok. Instead of List.text, it is List1.text
    VB Code:
    1. Private Sub List1_DblClick()
    2.  
    3.   MsgBox List1.text
    4.  
    5. End Sub

  13. #13
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: List Box

    Quote Originally Posted by Joacim Andersson
    Well, you don't have to double click the selected item for this code to run you could have double clicked an empty area in the ListBox which I think was what he referred to. ...
    No, that is NOT the case - if you click/dblclick on the "white" space in the listbox you won't get anything back ... only dblclicking on item will return "selected".

  14. #14
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: List Box

    Quote Originally Posted by RhinoBull
    No, that is NOT the case - if you click/dblclick on the "white" space in the listbox you won't get anything back ... only dblclicking on item will return "selected".
    Oh yeah, you're right. All my code for nothing . It's the ListView you can double click anywhere.

  15. #15
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: List Box

    That's exactly right!

  16. #16
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: List Box

    im confused..what is wrong with the code i posted? besides having a single click instead of dblclick?

  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: List Box

    Quote Originally Posted by |2eM!x
    im confused..what is wrong with the code i posted? besides having a single click instead of dblclick?
    Nothing.

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: List Box

    You changed the name of the standard listbox, although you tend to do that pretty often. I corrected it to List1.text

  19. #19
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: List Box

    And didn't read the post question carefully. It's cool. We all make mistakes.

  20. #20
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: List Box

    Quote Originally Posted by Jacob Roman
    And didn't read the post question carefully. It's cool. We all make mistakes.
    Yeah, I did one earlier in this thread

  21. #21
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: List Box

    i dont do it dg, stupid MZ tools does it or whatever that program is called..i wish i could turn that dang menu off...

    pisses me off so much!

  22. #22
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: List Box

    Quote Originally Posted by |2eM!x
    im confused..what is wrong with the code i posted? besides having a single click instead of dblclick?
    NOTHING really, "besides having a single click instead of dblclick" - that was meant to be a little joke but I'm afraid you took it seriously ...

  23. #23
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: List Box

    And the name of the Listbox too. Yeah take it easy |2eM!x. We were just pulling your chain. Everythings kool.

  24. #24
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: List Box

    Quote Originally Posted by Jacob Roman
    And the name of the Listbox too.
    Well you can name a ListBox simply List if you want to.

  25. #25
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: List Box

    Quote Originally Posted by RhinoBull
    It is WHAT !?
    Guy asked for DBLCLICK ... NOT SINGLE ...
    i totally thought you were serious

  26. #26
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: List Box

    Nah, not at this time - it's time for a little fun - 9 to 6 is when we should be serious ...

  27. #27
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: List Box

    Sometimes is fun to pick on |2eM!x. But I have my limits since I'm not a total creep.

  28. #28
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: List Box

    Quote Originally Posted by |2eM!x
    i dont do it dg, stupid MZ tools does it or whatever that program is called..i wish i could turn that dang menu off...

    pisses me off so much!
    You can turn it off, but a better answer would be not to rename variables or controls unless you give them meaningful names.

  29. #29
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: List Box

    im not gonna give it a meaningful name if im writing a 3 line code : /

  30. #30
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: List Box

    I think this thread is going nowhere and we should all stop replying as it was resolved many replies back.

  31. #31
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: List Box

    Quote Originally Posted by RhinoBull
    I think this thread is going nowhere and we should all stop replying as it was resolved many replies back.
    I agree! Let's stop. Rhino do you want to be the first that stops? If so please reply with a Yes otherwise please reply with a No.

  32. #32
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: List Box

    Ok I'll stop too. Wait a minute. I'm supposed to be in bed. ZZZZZZzzzzzzzzzz

  33. #33

    Thread Starter
    New Member PaK4LyFe's Avatar
    Join Date
    Apr 2005
    Posts
    10

    Re: List Box

    thank you all, but how do i make a form come up? Like in my program, I need a chatbox to popup and have certain information in there that i know how to do. And how do u make it so more then 1 chatbox appear with the info that I clicked on.
    For example, I DblClick on an Item in the list box that says someone's IP Address. Chatbox appears up. I dblclick anohter item with an IP address also, another chatbox pops up. So far i only got 1 chatbox poping up. I cant seem to get 2,3,4,5,etc....

    Hope i wasn't too confusing ....
    Last edited by PaK4LyFe; Apr 27th, 2005 at 02:45 PM.

  34. #34
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: List Box

    Post the code that you are using...

  35. #35

    Thread Starter
    New Member PaK4LyFe's Avatar
    Join Date
    Apr 2005
    Posts
    10

    Re: List Box

    Whne you dblclick on item in listbox:

    VB Code:
    1. Private Sub Friends_DblClick()
    2. MsgBox Friends.List(Friends.ListIndex)
    3. If vbOK = 1 Then
    4. Server.Show
    5. End If
    6. End Sub

    I dont need a msgbox, I just need the chatbox to open up with the info I cliked in the listbox. And another chatbox, with a differnt item in the listbox.

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