Results 1 to 7 of 7

Thread: listbox question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    listbox question

    ok guys 2 questions..

    1)
    VB Code:
    1. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If Button = vbRightButton Then
    3.         If List1.ListIndex > 0 Then
    4.             PopupMenu mnuOpen
    5.         End If
    6.     End If
    7. End Sub

    this should bring the popup up if i right click on an item in the listhbox, however it doesnt work for when i right click on the first item in the listbox.. the popup doesnt come up

    2)
    How can i add a vertical scrollbar to my listbox. at runtime if the listbox fills up with data quickly it automatically creates a horizontal scrollbar, but i need a vertical one too at the bottom of the listbox

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: listbox question

    VB Code:
    1. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If Button = vbRightButton Then
    3.         If List1.ListIndex [hl]=>[/hl] 0 Then
    4.             PopupMenu mnuOpen
    5.         End If
    6.     End If
    7. End Sub
    Show Appreciation. Rate Posts.

  3. #3
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: listbox question

    Quote Originally Posted by Pouncer
    ....need a vertical one too at the bottom of the listbox
    this sounds confusing, to me.
    ....at runtime if the listbox fills up with data quickly it automatically creates a horizontal scrollbar.....
    it creates a vertical scroll bar Pouncer, and not horizontal.

    i think you are trying to create a horizontal bar also, when the length of the text becomes longer then the width of the listbox. but i believe that it not possible with a listbox.
    Show Appreciation. Rate Posts.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: listbox question

    oh sorry yes horizontal

    its not possible??? damn

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: listbox question

    Quote Originally Posted by Harsh Gupta
    VB Code:
    1. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If Button = vbRightButton Then
    3.         If List1.ListIndex [hl]=>[/hl] 0 Then
    4.             PopupMenu mnuOpen
    5.         End If
    6.     End If
    7. End Sub
    doesnt work, the right click popup still doesnt come up on the first item in the list box

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: listbox question

    When you right click, the current item does not change. I assume you want the item that is clicked to become the selected item. The menu item chosen would then act on that item. In order to do that you need to use the following code.

    VB Code:
    1. Private Const LB_ITEMFROMPOINT = &H1A9
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    3.  
    4. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    5.     Dim lIndex  As Long
    6.     Dim lCoord  As Long
    7.  
    8.     If Button = vbRightButton Then
    9.         'Convert X, Y to Long coordinate fro lParam argument
    10.         '(Coordinate: HiWord=Y; LoWord=X)
    11.         lCoord = ((Y / Screen.TwipsPerPixelY) * &H10000) + (X / Screen.TwipsPerPixelX)
    12.        
    13.         'Now find the list item that was clicked
    14.         lIndex = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0&, ByVal lCoord)
    15.         'If success...
    16.         If lIndex >= 0 Then
    17.             'You now have the index of the item
    18.             List1.ListIndex = lIndex
    19.             MsgBox "You right clicked on " & List1.Text
    20.         End If
    21.     End If
    22. End Sub

  7. #7
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: listbox question

    you are right bruce, my suggestion wont work.
    Show Appreciation. Rate Posts.

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