DesktopPopupMenu

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from DesktopUIControl)


New in 2021r3

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

Events
Closing FocusLost MouseExit
ConstructContextualMenu FocusReceived MouseMove
ContextualMenuItemSelected KeyDown MouseUp
DragEnter KeyUp MouseWheel
DragExit MouseDown Opening
DragOver MouseDrag SelectionChanged
DropObject MouseEnter
Properties
Active fa-lock-32.png Italic RowCount fa-lock-32.png
AllowAutoDeactivate LastAddedRowIndex fa-lock-32.png Scope fa-lock-32.png
AllowTabStop LastRowIndex fa-lock-32.png SelectedRowIndex
Bold Left SelectedRowValue fa-lock-32.png
Enabled LockBottom TabIndex
FontName LockLeft Tooltip
FontSize LockRight Top
FontUnit LockTop Transparent
Handle fa-lock-32.png MouseCursor 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
Methods
AcceptFileDrop AddRowAt RemoveRowAt
AcceptPictureDrop AddSeparator RowTagAt
AcceptRawDataDrop Close RowValueAt
AcceptTextDrop DrawInto SelectRowWithTag
AddAllRows Refresh SelectRowWithValue
AddRow RemoveAllRows SetFocus

Notes

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

fa-info-circle-32.png
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.
fa-exclamation-circle-32.png
The MouseDown and MouseUp event handlers are never called on Linux due to a limitation of the underlying GtkComboBox that is used. [1]
fa-exclamation-circle-32.png
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 Opening 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
Me.AddRow(m)
Next

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

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

This code adds an item to PopupMenu:

PopupMenu1.AddRow("October")

This code populates the RowTag identifier with a sequence number:

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

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(item As String)
Var w As ListEditorWindow

If PopupMenu1.SelectedRowValue = "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:

TexField1.Text = PopupMenu1.RowTag(PopupMenu1.SelectedRowIndex)

See Also

DesktopComboBox, DesktopTextField controls; DesktopUIControl class.