From Xojo Documentation

Revision as of 18:32, 21 January 2022 by Gperlman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
For web apps, see WebPopupMenu.

Class (inherits from RectControl)

Displays a list of items when clicked. The user can select one item from the list. The ComboBox control is similar except that the user also has the option of typing an item instead of choosing one from the list of items.

Change DropObject MouseExit
Close GotFocus MouseMove
ConstructContextualMenu KeyDown MouseUp
ContextualMenuAction KeyUp MouseWheel
DragEnter LostFocus Open
DragExit MouseDown
DragOver MouseEnter
Active fa-lock-32.png LastRowIndex fa-lock-32.png Scope fa-lock-32.png
AllowAutoDeactivate Left SelectedRow fa-lock-32.png
AllowTabStop LockBottom SelectedRowIndex
Bold LockLeft TabIndex
Enabled LockRight Tooltip
FontName LockTop Top
FontSize MouseCursor Transparent
FontUnit MouseX fa-lock-32.png TrueWindow fa-lock-32.png
Handle fa-lock-32.png MouseY fa-lock-32.png Underline
Height Name fa-lock-32.png Visible
Index fa-lock-32.png PanelIndex Width
InitialValue fa-lock-32.png Parent Window fa-lock-32.png
Italic RowCount fa-lock-32.png
LastAddedRowIndex fa-lock-32.png RowValueAt fa-lock-32.png
AcceptFileDrop AddRowAt RemoveAllRows
AcceptPictureDrop AddSeparator RemoveRowAt
AcceptRawDataDrop Close RowTagAt
AcceptTextDrop DrawInto SelectRowWithTag
AddAllRows Invalidate SelectRowWithValue
AddRow Refresh SetFocus


Use the constant NoSelection (-1) to indicate that no rows are selected.

Changing the Height property has no effect for apps run on macOS. As a native control, macOS always draws the PopupMenu at its system-standard height.
The MouseDown and MouseUp event handlers are never called on Linux due to a limitation of the underlying GtkComboBox that is used. [1]
ContextualMenus do not work with PopupMenu on macOS due to a limitation of the underlying macOS control that is used.

Sample Code

This code in the Open event handler populates a popup menu and sets the initial value to the current month:

Var months() As String = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
For Each m As String In months

Var d As New Date
Me.SelectedRowIndex = d.Month - 1 // Select current month

Examine the value of SelectedRowIndex in the Change event handler to determine which item was selected.

This code adds an item to PopupMenu:


This code populates the RowTag identifier with a sequence number:

For i As Integer =0 To Me.LastRowIndex
Me.RowTag(i) = i

Since RowTag is a Variant, you must first convert it to an Integer if you want to compare it to another integer. Do this with a simple assignment statement such as:

Var recID As Integer
recID = PopupMenu1.RowTag(1)

Then compare recID to another Integer.

This code opens a new window when an item is chosen.

Sub SelectionChanged()
Var w As ListEditorWindow

If PopupMenu1.Value = "Edit List..." Then
w = New ListEditorWindow
End If

Changing the selected item in a PopupMenu:

PopupMenu1.SelectedRowIndex = 3 // Selects the 4th row in the list (0-based)

Displaying the RowTag of the selected menu item:

TextField1.Value = PopupMenu1.RowTag(PopupMenu1.SelectedRowIndex)

See Also

BevelButton, ComboBox, TextField controls; RectControl class.