Hi, i'm using the code below. It works well, however the data displayed on that menu is more than 300 (data is coming from database). Is there anyway to put vertical scroll bar on the popupmenu? Thanks in advance.
Code:
Private Sub lvList_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim li As MSComctlLib.ListItem
If Button = 2 Then
Set li = lvList.HitTest(x, y)
If Not li Is Nothing Then
Me.PopupMenu mnuTeams
End If
Set li = Nothing
End If
End Sub
I don't think it is good idea to show very long list as a popup menu, instead you can use different controls to work like popup menu, e.g. ListBox in a separate form.
That's a lot of tings to choose from in a popup menu...that's a lot to choose from in ANY menu.
Is there any way to pare it down some?
-tg
I was actually considering grouping them but I will still have more than 50+ groups afterwards (which i guess is still long for a popupmenu)
Originally Posted by 4x2y
Standard context menu can't have a scroll bar.
I don't think it is good idea to show very long list as a popup menu, instead you can use different controls to work like popup menu, e.g. ListBox in a separate form.
You are correct. I also realized that long popup menu is not good idea. Thanks
Well the system default popup menus scroll bars are a little different, they *do* however have a functional scroll, or the alternative of going with columns. They're just tricky to get VB to cooperate with. You can have a scroll button:
This style, however, has to be set via API. I believe you can get the hMenu for a native VB PopupMenu so you don't have to create the whole thing for scratch, maybe you or someone knows/will look up, but once you have the hMenu, here's how to set a maximum height after which the scroll buttons appear:
Code:
Dim mnfo As MENUINFO
mnfo.cbSize = Len(mnfo)
mnfo.fMask = MIM_MAXHEIGHT
mnfo.cyMax = 300 'desired height in pixels
SetMenuInfo hMenu, mnfo
You other option is that the menus can support multiple columns...
You're going to have to insert items that start a new column by API however. For the picture above the Rename item starts a new column:
Code:
Dim mii As MENUITEMINFOW
'[...]
With mii
.cbSize = Len(mii)
'Rename
.fMask = MIIM_ID Or MIIM_TYPE
.fType = MFT_MENUBARBREAK Or MFT_STRING
.wID = idFS_Rename
.cch = Len(sRN)
.dwTypeData = StrPtr(sRN)
Call InsertMenuItemW(hMenu, 12, True, mii)
End With
Note that as mentioned, it's generally a poor UI design choice to resort to these options. But they're present.
---
PS- One final caveat, I'm not entirely sure if these methods work with the old-fashioned menus you get if your app doesn't have a common controls 6 manifest, but with LaVolpe's new manifest maker being even easier to use than the original, there's just no excuse not to have a manifest unless your app won't be used on any OS newer than Win2k or WinME.
Here's the supporting API declares for the code in this post:
Code:
Public Type MENUINFO
cbSize As Long
fMask As MI_Mask
dwStyle As MI_Style
cyMax As Long
hbrBack As Long
dwContextHelpID As Long
dwMenuData As Long
End Type
Public Enum MI_Mask
MIM_MAXHEIGHT = &H1
MIM_BACKGROUND = &H2
MIM_HELPID = &H4
MIM_MENUDATA = &H8
MIM_STYLE = &H10
MIM_APPLYTOSUBMENUS = &H80000000
End Enum
Public Enum MI_Style
MNS_CHECKORBMP = &H4000000
MNS_NOTIFYBYPOS = &H8000000
MNS_AUTODISMISS = &H10000000
MNS_DRAGDROP = &H20000000
MNS_MODELESS = &H40000000
MNS_NOCHECK = &H80000000
End Enum
Public Type MENUITEMINFOW
cbSize As Long
fMask As MII_Mask
fType As MF_Type ' MIIM_TYPE
fState As MF_State ' MIIM_STATE
wID As Long ' MIIM_ID
hSubMenu As Long ' MIIM_SUBMENU
hbmpChecked As Long ' MIIM_CHECKMARKS
hbmpUnchecked As Long ' MIIM_CHECKMARKS
dwItemData As Long ' MIIM_DATA
dwTypeData As Long ' MIIM_TYPE
cch As Long ' MIIM_TYPE
hbmpItem As Long
End Type
Public Enum MII_Mask
MIIM_STATE = &H1
MIIM_ID = &H2
MIIM_SUBMENU = &H4
MIIM_CHECKMARKS = &H8
MIIM_TYPE = &H10
MIIM_DATA = &H20
MIIM_BITMAP = &H80
MIIM_STRING = &H40
End Enum
' win40 -- A lot of MF_* flags have been renamed as MFT_* and MFS_* flags
Public Enum MenuFlags
MF_INSERT = &H0
MF_ENABLED = &H0
MF_UNCHECKED = &H0
MF_BYCOMMAND = &H0
MF_STRING = &H0
MF_UNHILITE = &H0
MF_GRAYED = &H1
MF_DISABLED = &H2
MF_BITMAP = &H4
MF_CHECKED = &H8
MF_POPUP = &H10
MF_MENUBARBREAK = &H20
MF_MENUBREAK = &H40
MF_HILITE = &H80
MF_CHANGE = &H80
MF_END = &H80 ' Obsolete -- only used by old RES files
MF_APPEND = &H100
MF_OWNERDRAW = &H100
MF_DELETE = &H200
MF_USECHECKBITMAPS = &H200
MF_BYPOSITION = &H400
MF_SEPARATOR = &H800
MF_REMOVE = &H1000
MF_DEFAULT = &H1000
MF_SYSMENU = &H2000
MF_HELP = &H4000
MF_RIGHTJUSTIFY = &H4000
MF_MOUSESELECT = &H8000&
End Enum
Public Enum MF_Type
MFT_STRING = MF_STRING
MFT_BITMAP = MF_BITMAP
MFT_MENUBARBREAK = MF_MENUBARBREAK
MFT_MENUBREAK = MF_MENUBREAK
MFT_OWNERDRAW = MF_OWNERDRAW
MFT_RADIOCHECK = &H200
MFT_SEPARATOR = MF_SEPARATOR
MFT_RIGHTORDER = &H2000
MFT_RIGHTJUSTIFY = MF_RIGHTJUSTIFY
End Enum
Public Enum MF_State
MFS_GRAYED = &H3
MFS_DISABLED = MFS_GRAYED
MFS_CHECKED = MF_CHECKED
MFS_HILITE = MF_HILITE
MFS_ENABLED = MF_ENABLED
MFS_UNCHECKED = MF_UNCHECKED
MFS_UNHILITE = MF_UNHILITE
MFS_DEFAULT = MF_DEFAULT
End Enum
Public Declare Function InsertMenuItemW Lib "user32" (ByVal hMenu As Long, ByVal uItem As Long, ByVal fByPosition As Boolean, lpmii As MENUITEMINFOW) As Boolean
Public Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, lpcmi As MENUINFO) As Long
Last edited by fafalone; Jun 13th, 2017 at 07:24 PM.
Reason: Initially forgot about scroll buttons in this post. Updated with that option.