Class

WebPopupMenu


Description

A standard popup menu control.

Methods

Name

Parameters

Returns

Shared

AddAllRows

items() As String

AddRow

item As String, tag As Variant = Nil

AddRowAt

item As Integer

AddSeparator

Close

ExecuteJavaScript

Script As String

GotoURL

URL As String, inNewWindow As Boolean = False

RemoveAllRows

RemoveRowAt

index As Integer

RowTagAt

index As Integer

Variant

RowTextAt

index As Integer

String

SelectRowWithTag

targetValue As Variant

SelectRowWithText

targetText As String

SetFocus

Style

WebStyle

Assigns style As WebStyle

UpdateBrowser

Events

Name

Parameters

Returns

Closed

ContextualMenuSelected

hitItem As WebMenuItem

Hidden

Opening

SelectionChanged

item As WebMenuitem

Shown

Property descriptions


WebPopupMenu.ContextualMenu

ContextualMenu As WebMenuItem

If you assign a WebMenuItem to the control, it will be displayed when the user right-clicks the control.

On a WebPage, you can disable/remove the default contextual menu by an empty WebMenuItem class object to this property.

This code populates a contextual menu in the Shown event of the control.

Var menu As New WebMenuItem

menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu

The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:

Select Case hitItem.Text
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebPopupMenu.ControlID

ControlID As String

Identifies the control on a per session basis.

This property is read-only.


WebPopupMenu.Enabled

Enabled As Boolean

When True the WebControl is drawn enabled and responds to user action. When False, the control appears as disabled and does not respond to user actions.

In the case of WebTimer, when set to False this disables and stops the WebTimer. When set to True, it starts the WebTimer.

Disable a button when a check box value changes:

If AllowSaveCheckBox.Value Then
  SaveButton.Enabled = True
Else
  AllowSaveButton.Enabled = False
End If

WebPopupMenu.Height

Height As Integer

The height (in pixels) of the control.


WebPopupMenu.Indicator

Indicator As Indicators

The color scheme for the control.


WebPopupMenu.LastAddedRowIndex

LastAddedRowIndex As Integer

The number of the last row added with the AddRow or AddRowAt method.

This property is read-only.

If no rows have been added, LastAddedRowIndex will be -1.


WebPopupMenu.LastRowIndex

LastRowIndex As Integer

The index of the last row of the WebPopupMenu.

This property is read-only.


WebPopupMenu.Left

Left As Integer

The position of the left side of the WebUIControl in pixels, relative to the web page.


WebPopupMenu.LockBottom

LockBottom As Boolean

Determines whether the bottom edge of the control should stay at a set distance from the bottom edge of the parent control, if there is one, or the owning web page.

This property is read-only.


WebPopupMenu.LockHorizontal

LockHorizontal As Boolean

LockHorizontal overrides LockLeft and LockRight. It allows you to proportionally lock a control's position to the center of its parent control (or web page).

This property is read-only.

For example, if you place a control in the center of the page and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.


WebPopupMenu.LockLeft

LockLeft As Boolean

Determines whether the left edge of the control should stay at a set distance from the left edge of the parent control, if there is one, or the owning web page.

This property is read-only.


WebPopupMenu.LockRight

LockRight As Boolean

Determines whether the right edge of the control should stay at a set distance from the right edge of the parent control, if there is one, or the owning web page.

This property is read-only.


WebPopupMenu.LockTop

LockTop As Boolean

Determines whether the top edge of the control should stay at a set distance from the top edge of the parent control, if there is one, or the owning web page.

This property is read-only.


WebPopupMenu.LockVertical

LockVertical As Boolean

LockVertical overrides LockTop and LockBottom. It allows you to proportionally lock a control's position to keep it centered within the parent control or web page.

This property is read-only.

For example, if you place a control in the center of the page, and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.


WebPopupMenu.Name

Name As String

The name of the control.

This property is read-only.


WebPopupMenu.Page

Page As WebPage

Identifies the web page that contains the control.

This property is read-only.


WebPopupMenu.Parent

Parent As WebView

Used to get the control's parent control or page. If the parent control is a WebContainer, then it returns the WebContainer. If it is on a WebPage, it returns the WebPage.

This property is read-only.


WebPopupMenu.RowCount

RowCount As Integer

The number of rows in the WebPopupMenu.

This property is read-only.


WebPopupMenu.SelectedRowIndex

SelectedRowIndex As Integer

The number of the selected row.

If no item is selected, SelectedRowIndex returns -1.

If the SelectedRowIndex is set to a value less than -1 or greater than the last index, an OutOfBoundsException will occur.

To clear the selected item, set SelectedRowIndex = -1.

The following code in the SelectionChanged event handler displays the text from the selected row:

If Me.SelectedRowIndex >= 0 Then
  MessageBox(Me.RowAt(Me.SelectedRowIndex))
End If

The following code displays a message if no row is selected:

If TypePopup.SelectedRowIndex = -1 Then
  MessageBox("Please select a row first.")
End If

WebPopupMenu.SelectedRowText

SelectedRowText As String

Returns the value of the currently selected row.

This property is read-only.


WebPopupMenu.TabIndex

TabIndex As Integer

The WebUIControl's control's position in the Tab Order. The control with a TabIndex of 0 is the first WebUIControl to get the focus when the page opens in the browser.

This example sets the control's TabIndex.

Me.TabIndex = 2

WebPopupMenu.Tooltip

Tooltip As String

Text of a message displayed as a tooltip.

The tip is displayed when the user places the mouse on the control and leaves it there.

This code in the Shown event of a Button sets the tooltip:

Me.Tooltip = "Save changes"

WebPopupMenu.Top

Top As Integer

The top of the control in local coordinates relative to the web page.


WebPopupMenu.Visible

Visible As Boolean

If True, the control is drawn. If False, it's not.

Hide a control based on a checkbox setting:

If ShowEmailCheckbox.Value Then
  EmailField.Visible = True
Else
  EmailField.Visible = False
End If

WebPopupMenu.Width

Width As Integer

The width (in pixels) of the web control.

This code in the Shown event handler increases the size of the control:

Me.Width = Me.Width + 50

Method descriptions


WebPopupMenu.AddAllRows

AddAllRows(items() As String)

Adds all rows in the array passed to the menu of the control.

A ParamArray can also be passed.

Add a new rows to the popup menu in the Shown event handler:

Var people() As String
people.AddRow("Fred")
people.AddRow"(Wilma")
PeoplePopup.AddAllRows(people)

Adds the new rows from a ParamArray:

PeoplePopup.AddAllRows("Fred", "Wilma")

WebPopupMenu.AddRow

AddRow(item As String, tag As Variant = Nil)

Adds item to the end of the list of items. If the optional tag is included, the value is assigned to the Tag property of the WebMenuItem.

Passing a WebMenuItem allows the menu item to utilize all of the features of a WebMenuItem including changing the color, disabling the item, using styles, creating hierarchical menus and more.

Add a new rows to the popup menu in the Shown event handler:

Me.AddRow("One")
Me.AddRow("Two")
Me.AddRow("Three")
Me.AddRow("Four")

This example, also in the Shown event handler, adds a item to the WebPopupMenu using a WebMenuItem in order to set the TextColor to blue:

Var item As New WebMenuItem("Police")
item.TextColor = Color.Blue
Me.AddRow(menu)

WebPopupMenu.AddRowAt

AddRowAt(item As Integer)

Creates a new row at item, moving the existing rows below index down. The item in this case is a WebMenuItem.

The following example adds a row at above a specific row in the PopupMenu* from another control:

PopupMenu1.AddRowAt(1, "Steven")

This example adds an item using a WebMenuItem in order to set the TextColor to blue.

Var item As New WebMenuItem("Police")
item.TextColor = Color.Blue
PopupMenu1.AddRowAt(1, item)

WebPopupMenu.AddSeparator

AddSeparator

Adds a non-selectable line to the menu separating the rows above and below it.

Add a new two rows followed by a separator, followed by two more rows to the popup menu in the Shown event handler:

Me.AddRow("Frodo")
Me.AddRow("Sam")
Me.AddSeparator
Me.AddRow("Miri")
Me.AddRow("Pippin")

WebPopupMenu.Close

Close

Removes the control from the page.


WebPopupMenu.ExecuteJavaScript

ExecuteJavaScript(script As String)

Executes the JavaScript passed. The JavaScript passed can call a JavaScript function in a WebPageSource control.

The Xojo web framework uses EcmaScript 6 which is more strict than previous versions of JavaScript. For more details, see the EcmaScript 6 documentation.

This code in the Pressed event of a Button displays an alert using JavaScript:

Me.ExecuteJavaScript("alert('Hello!');")

This code will select the text in a WebTextField (or WebTextArea):

WebTextField1.ExecuteJavascript("document.getElementById('" + _
  WebTextField1.ControlID + "_inner').select();")

WebPopupMenu.GotoURL

GotoURL(URL As String, inNewWindow As Boolean = False)

Opens the passed URL in place of the current web page or downloads a file. If InNewWindow is True, the browser is asked to open the URL in a new window.

If the browser has popup windows disabled and InNewWindow is True, the method silently fails and the page is not shown.

If InNewWindow is False, the running web app is replaced with the specified URL. If you want to display an external web site within your web app, use the WebHTMLViewer control.

Display a web site in a new popup window:

Me.GotoURL("http://www.wikipedia.org", True)

WebPopupMenu.RemoveAllRows

RemoveAllRows

Removes all rows in the WebPopupMenu, including any initial values that were specified in the IDE.

This example removes all the rows in PopupMenu1.

PopupMenu1.RemoveAllRows

WebPopupMenu.RemoveRowAt

RemoveRowAt(index As Integer)

Removes the specified row at index.

This example removes the last row.

PopupMenu1.RemoveRowAt(PopupMenu1.LastRowIndex)

WebPopupMenu.RowTagAt

RowTagAt(index As Integer) As Variant

Gets and sets the RowTag for the row at the index passed.

This example code sets the tag for the last row in the popup menu to the value of a variable called rowID:

PeoplePopup.RowTagAt(PeoplePopup.LastRowIndex) = rowID

To get the tag:

rowID = PeoplePopup.RowTagAt(PeoplePopup.LastRowIndex)

WebPopupMenu.RowTextAt

RowTextAt(index As Integer) As String

Returns the text from the menu at the index passed.

The following example code displays in a MessageBox the contents of the last row in the menu:

MessageBox(PopupMenu1.RowTextAt(PopupMenu1.LastRowIndex))

WebPopupMenu.SelectRowWithTag

SelectRowWithTag(targetValue As Variant)

Selects the first row whose tag matches the targetValue passed.


WebPopupMenu.SelectRowWithText

SelectRowWithText(targetText As String)

Selects the row with the provided targetText.

If targetText is not found, an InvalidArgumentException is raised.


WebPopupMenu.SetFocus

SetFocus

Sets the focus to the Control.

This code checks for a required value when a button is pressed:

If UserNameField.Text.IsEmpty Then
  MessageBox("Please enter your UserName.")
  UserNameField.SetFocus
  Return
End If

WebPopupMenu.Style

Style As WebStyle

Returns the WebStyle for the control.


Style(Assigns style As WebStyle)

Assigns the style to the control.

In this example, in any event of the control, set the text to bold:

Var style As New WebStyle
style.Bold = True
Me.Style = style

WebPopupMenu.UpdateBrowser

UpdateBrowser

Forces the current values of the control to be sent to the browser.

This method is useful when you are computing values in a loop and wish to update the browser immediately rather than wait until the current method ends.

This code iterates through a RowSet of database rows, updates a WebProgressBar and then forces the updated WebProgressBar to be sent to the browser via UpdateBrowser.

ProgressBar1.Maximum = SalesData.RowCount
For Each row As DatabaseRow in SalesData
 AnalyzeSales(row)
 ProgressBar1.Value = ProgressBar1.Value + 1
 ProgressBar1.UpdateBrowser
Next

Event descriptions


WebPopupMenu.Closed

Closed

The control has been removed from the browser either because the page has closed or the control's Close method was called.


WebPopupMenu.ContextualMenuSelected

ContextualMenuSelected(hitItem As WebMenuItem)

Called when a contextual menu item is selected. This selected item is contained in hitItem.

This code populates a contextual menu in the Opening event of a WebToolbar:

Var menu As New WebMenuItem

menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu

The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:

Select Case hitItem.Text
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebPopupMenu.Hidden

Hidden

The control is about to become no longer visible. This could be because the page is being closed, is being replaced as the foreground page by another page or because the control or a parent control's Visible property has been set to False.

Note

This event is equivalent to the DesktopWindow.Deactivated event in a desktop app.


WebPopupMenu.Opening

Opening

The control has been created and the page is opening but has not been sent to the browser yet.

The Opening event handler can be used to initialize non-visual properties and settings for controls.

In most cases, you should use the Shown event to initialize controls.


WebPopupMenu.SelectionChanged

SelectionChanged(item As WebMenuitem)

The selected item has changed, either by user interaction with the control or via code. Use SelectedRowIndex to change the selection via code.

This is the equivalent of the desktop PopupMenu's SelectionChanged event. It is past tense to reflect the fact that the change has already occurred when the event is called.

Note

The WebMenuitem passed to this event is a copy of the one that was actually selected making the orginal effectively immutable.

This code in the SelectionChanged event handler displays the selected item:

If item <> Nil Then
  MessageBox("You selected: " + item.Text)
End If

WebPopupMenu.Shown

Shown

The control has appeared on the currently displayed page. This could be because its parent page just finished loading, its parent page has come to the foreground or the control is now visible having been previously invisible because it or its parent control's Visible property has been set to True.

Use the Shown event for initializing your controls or doing anything that would interact with other controls or user interface elements on the web page instead of the Opening event.

Note

This event is the web equivalent to the DesktopWindow.Activated event.

This code in the Shown event of a WebListBox adds 2 rows with 3 columns:

Me.RemoveAllRows
Me.AddRow("Row 1", "Bob", "Roberts")
Me.AddRow("Row 2", "Barb", "Reynolds")

This example sets the text of a label:

If Session.LoggedIn Then
  Me.Text = "Welcome!"
Else
  Me.Text = "Welcome, " + Session.UserName
End If

Sample code

Add several items to the popup menu in its Shown event handler:

Me.AddRow("One")
Me.AddRow("Two")
Me.AddRow("Three")
Me.AddRow("Four")

Compatibility

Web projects on all supported operating systems.

See also

WebUIControl parent class; WebComboBox, DesktopPopupMenu, DesktopComboBox controls.