|
-
Dec 3rd, 2005, 12:45 PM
#1
Thread Starter
Frenzied Member
listbox question
ok guys 2 questions..
1)
VB Code:
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
If List1.ListIndex > 0 Then
PopupMenu mnuOpen
End If
End If
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
-
Dec 3rd, 2005, 12:58 PM
#2
Re: listbox question
VB Code:
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
If List1.ListIndex [hl]=>[/hl] 0 Then
PopupMenu mnuOpen
End If
End If
End Sub
-
Dec 3rd, 2005, 01:02 PM
#3
Re: listbox question
 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.
-
Dec 3rd, 2005, 02:14 PM
#4
Thread Starter
Frenzied Member
-
Dec 3rd, 2005, 02:51 PM
#5
Thread Starter
Frenzied Member
Re: listbox question
 Originally Posted by Harsh Gupta
VB Code:
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
If List1.ListIndex [hl]=>[/hl] 0 Then
PopupMenu mnuOpen
End If
End If
End Sub
doesnt work, the right click popup still doesnt come up on the first item in the list box
-
Dec 3rd, 2005, 03:07 PM
#6
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:
Private Const LB_ITEMFROMPOINT = &H1A9
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
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lIndex As Long
Dim lCoord As Long
If Button = vbRightButton Then
'Convert X, Y to Long coordinate fro lParam argument
'(Coordinate: HiWord=Y; LoWord=X)
lCoord = ((Y / Screen.TwipsPerPixelY) * &H10000) + (X / Screen.TwipsPerPixelX)
'Now find the list item that was clicked
lIndex = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0&, ByVal lCoord)
'If success...
If lIndex >= 0 Then
'You now have the index of the item
List1.ListIndex = lIndex
MsgBox "You right clicked on " & List1.Text
End If
End If
End Sub
-
Dec 4th, 2005, 06:03 AM
#7
Re: listbox question
you are right bruce, my suggestion wont work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|