メインコンテンツまでスキップ
バージョン: 次へ

ドロップダウンリスト

ドロップダウンリストは、ユーザーがリストから選択をおこなえるようにするためのフォームオブジェクトです。ドロップダウンリストに表示される項目は、オブジェクト、配列、選択リスト、または標準アクションを用いて管理します。

macOS においては、ドロップダウンリストは "ポップアップメニュー" とも呼ばれます。どちらの名前も同じタイプのオブジェクトを指します。 As the following example shows, the appearance of these objects can differ slightly according to the platform and the selected flyout mode:

  • macOS with "pop-up" flyout mode:

  • Windows with "pull-down" flyout mode (FluentUI rendering required):

  • Windows (Classic rendering):

ドロップダウンリストの種類​

それぞれに特有の機能を持つ、複数タイプのドロップダウンリストを作成することができます。タイプを定義するには、プロパティリストで適切な 式の型 と データタイプ の値を選択するか、それらに相当する JSON を指定します。

型機能式の型/式タイプデータタイプJSON 定義
Objectコレクションに基づくObjectNumeric, Text, Date, または TimedataSourceTypeHint: object + numberFormat: <format> または textFormat: <format> または dateFormat: <format> または timeFormat: <format>
配列配列に基づく配列Numeric, Text, Date, または TimedataSourceTypeHint: arrayNumber または arrayText または arrayDate または arrayTime
選択リスト (値を保存)選択リストに基づく (標準)リスト選択された項目値dataSourceTypeHint: text + saveAs: value
選択リスト (参照を保存)選択リストに基づく(項目の位置を保存)リスト選択された項目参照dataSourceTypeHint: integer + saveAs: reference
階層型選択リスト階層型の表示が可能リストリスト参照dataSourceTypeHint: integer
標準アクションアクションにより自動生成anyリスト参照以外いずれかの定義 + action: <action> (他エリアに適用されるアクションの場合は + focusable: false)

ドロップダウンリストの使い方​

オブジェクトの使用​

この機能は 4Dプロジェクトでのみ利用可能です。

履歴
リリース内容
21 R6Support of styled, editable items

ドロップダウンリストのデータソースとして、コレクション を内包した オブジェクト を使用できます。このオブジェクトには、次のプロパティが格納されていなくてはなりません:

プロパティ型説明
valuesCollectionMandatory - Collection of entries used to build the list. Entries can be either scalar values or objects (see below). Scalar values must use one consistent data type across selectable values (text, integer, boolean, date, or time). If empty or undefined, the drop-down displays no items.
indexnumberIndex of the currently selected item in the full values collection (0-based). Non-selectable items and separator items keep their position and are counted in index. -1 に設定すると、プレースホルダー文字列として currentValue が表示されます。
currentValueSame scalar type as selected valueCurrently selected scalar value (used as placeholder value if set by code). For object entries, this is the entry's value property, not the whole object.

Additional properties at the top level of the data source object are ignored by the drop-down renderer.

ドロップダウンリストに関連付けるオブジェクトを初期化するには、次の方法があります:

  • Enter a list of default values in the object properties by selecting <Static List> in the Data Source theme of the Property List. これらのデフォルト値は、オブジェクトへと自動的にロードされます。

  • オブジェクトとそのプロパティを作成するコードを実行します。

Example with scalar values​

If "Form.myDrop" is the expression associated to the drop-down list, you can write in the On Load form event:

// Form.myDrop はフォームオブジェクトのデータソースです

Form.myDrop:=New object
Form.myDrop.values:=New collection("apples"; "nuts"; "pears"; "oranges"; "carrots")
Form.myDrop.index:=-1 // currentValue をプレースホルダーに使います
Form.myDrop.currentValue:="フルーツを選択してください"

ドロップダウンリストには、プレースホルダー文字列が表示されます:

ユーザーによって項目が選択されると:

Form.myDrop.values // ["apples","nuts","pears","oranges","carrots"]
Form.myDrop.currentValue //"oranges"
Form.myDrop.index //3

Customizing items with object entries​

互換性

On Windows, item customization is only available in forms rendererd with Fluent UI.

Inside the values collection of objects, each entry can be an object which defines item-level presentation and behavior:

Item property型説明
values[].valueText, Integer, Boolean, Date, or TimeScalar value represented by the item. If selectable, this value can become currentValue. If omitted and separator is not true, the item is displayed with no label.
values[].selectableBoolean任意。 Default: true. When false, the item is visible but cannot be selected.
values[].picture4D.File, Picture, or TextOptional icon/picture. A text value must be a valid picture path.
values[].fontWeightText任意。 "normal" or "bold".
values[].fontStyleText任意。 "normal" or "italic".
values[].colorText or IntegerOptional text color. Supports CSS color names, hexadecimal color strings, RGB strings, and RGB integer values.
values[].separatorBoolean任意。 Default: false. When true, the item is rendered as a separator and all other item properties are ignored.

Rendering and precedence rules​

  • If separator = true, the item is always rendered as a non-selectable divider. In this case value, selectable, picture, color, fontWeight, and fontStyle are ignored.
  • A "-" scalar text value is interpreted as a separator (compatibility). A "-" as a .value property in an object entry is interpreted as a regular label, not a separator.
  • If value is omitted and separator is not true, the item has no text label.
  • color, fontWeight, and fontStyle are applied only when a value is displayed.
  • If selectable is omitted, it behaves as true.
  • Non-selectable items and separator items remain in the values collection and keep their original index positions.

Platform notes for non-selectable items​

When selectable is false:

  • On Windows, if color is explicitly set, that color is rendered unchanged; if color is not set, the item appears gray.
  • On macOS, non-selectable items are alpha-blended, including when color is set.

Picture placement​

For non-separator items with a picture:

  • Left/center-aligned items: picture is displayed on the left of the value.
  • Right-aligned items: picture is displayed on the right of the value.
  • If value is omitted, the picture is displayed alone.
Technical limitation

The picture is always displayed on the left with hierarchical list data source on Windows or macOS.

Example with mixed scalar and object entries​

// Form.myDrop is the datasource of the form object

Form.myDrop:=New object
Form.myDrop.values:=New collection

// Non-selectable title
Form.myDrop.values.push({value: "Priority"; selectable: False})

// Selectable styled items
Form.myDrop.values.push({value: "Urgent"; picture: File("/RESOURCES/icons/urgent.png"); color: "#C42B1C"; fontWeight: "bold"})
Form.myDrop.values.push({value: "Normal"; fontWeight: "bold"})
Form.myDrop.values.push("Low")

// Visual separator
Form.myDrop.values.push({separator: True})

// Non-selectable message
Form.myDrop.values.push({value: "Information"; selectable: False; fontStyle: "italic"})

// Placeholder mode
Form.myDrop.index:=-1
Form.myDrop.currentValue:="Select a level"

ユーザーによって項目が選択されると:

変数が 1 のとき、列は昇順で並べ替えられており、並べ替え矢印が表示されています。

//Form.myDrop.currentValue = "Normal"
//Form.myDrop.index = 2

配列の使用​

配列 とは、メモリ内の値のリストのことで、配列の名前によって参照されます。ドロップダウンリストをクリックすると、その配列を値のリストとして表示します。

ドロップダウンリストに関連付ける配列を初期化するには、次の方法があります:

  • プロパティリストの データソース テーマにおいて、選択リストの項目で \<Static List> を選び、デフォルト値のリストを入力します。これらのデフォルト値は、配列へと自動的にロードされます。オブジェクトに関連付けた変数名を使用して、この配列を参照することができます。

  • オブジェクトが表示される前に、値を配列要素に代入するコードを実行します。例:

ARRAY TEXT(aCities;6)
aCities{1}:="Philadelphia"
aCities{2}:="Pittsburg"
aCities{3}:="Grand Blanc"
aCities{4}:="Bad Axe"
aCities{5}:="Frostbite Falls"
aCities{6}:="Green Bay"

この場合、フォームのオブジェクトに紐付けた 変数 は aCities でなければなりません。このコードをフォームメソッド内に置き、On Load フォームイベント発生時に実行されるようにします。

  • オブジェクトが表示される前に、LIST TO ARRAY コマンドを使ってリストの値を配列にロードします。例:
LIST TO ARRAY("Cities";aCities)

この場合にも 、フォームのオブジェクトに紐付けた 変数 は aCities でなければなりません。このコードは、前述した代入命令文の代わりに実行できます。

ユーザーがおこなった選択内容をフィールドに保存する必要があれば、レコードの登録後に代入命令を実行します。たとえば、次のような Case文のコードを作成します:

Case of
:(Form event=On Load)
LIST TO ARRAY("Cities";aCities)
If(Record number([People])<0) // 新規レコードなら
aCities:=3 // デフォルト値を表示
Else // 既存レコードの場合、保存された値を表示
aCities:=Find in array(aCities;City)
End if
:(Form event=On Clicked) // ユーザーがセレクションを変更した場合
City:=aCities{aCities} // フィールドに新しい値を代入
:(Form event=On Validate)
City:=aCities{aCities}
:(Form event=On Unload)
CLEAR VARIABLE(aCities)
End case

プロパティリストのイベントテーマにおいて、作成した Case 文の中で使用する各イベントを選択して有効化ます。配列には常に有限数の項目が納められます。項目リストは動的であり、メソッドを用いて変更可能です。配列の項目は変更・並び替え・追加することができます。

選択リストの使用​

入力エリア (列挙型のフィールドまたは変数) の管理のためにリストボックスを使用したい場合、フィールドまたは変数をドロップダウンリストの データソース として直接参照することができます。これにより列挙型のフィールド/変数を容易に管理できるようになります。

たとえば、"White"、"Blue"、"Green"、"Red" という値のみを含む "Color" というフィールドがあった場合、これらの値を含むリストを作成し、それを "Color" フィールドを参照するドロップダウンリストに関連付けることができます。こうすることによって、あとは 4D が自動的にカレント値の入力や表示に関して管理してくれます。

階層リストの場合、第一階層の値のみが表示・選択できます。階層的な内容を表示したい場合は、階層型の選択リスト を使用する必要があります。

ドロップダウンリストをフィールドや変数と関連付けるには、プロパティリストの 変数あるいは式 欄にフィールドまたは変数の名前を直接入力します。

この原理は、オブジェクトや配列を用いたドロップダウンリストと組み合わせることはできません。"変数あるいは式" の欄にフィールド名を入力した場合は、必ず選択リストを使用します。

フォームを実行すると、4D が自動的に入力中または表示中のドロップダウンリストの状態を管理します。 ユーザーが値を選択すると、その値はフィールドに保存され、このフィールドの値はフォームが表示されたときにドロップダウンリスト表示されます:

選択された項目値 または 選択された項目参照​

選択リスト型のドロップダウンリストをフィールドや変数と関連付けた場合、データタイプ プロパティを 選択された項目値 または 選択された項目参照 に設定することができます。このオプションにより、保存するデータのサイズを最適化できるようになります。

階層型選択リストの使用​

階層型ドロップダウンリストは、リストの各項目にサブリストが関連付けられています。以下は、階層型ドロップダウンリストの例です:

階層型選択リストをドロップダウンリストオブジェクトに割り当てるには、プロパティリストの 選択リスト 欄を使います。

階層型ドロップダウンリストの管理には、4Dランゲージの 階層リスト コマンドを使用します。 (*; "name") シンタックスをサポートするコマンドであれば全て、階層型ドロップダウンリストに使用できます (例: List item parent)。

標準アクションの使用​

標準アクション を使って、ドロップダウンリストを自動的に構築することができます。この機能は、以下のコンテキストでサポートされています:

  • gotoPage 標準アクションの使用。この場合、4D は選択された項目の番号に対応する フォームのページ を自動的に表示します。たとえば、ユーザーが 3番目の項目をクリックすると、4Dはカレントフォームの 3ページ目 (存在する場合) を表示します。実行時のデフォルトでは、ドロップダウンリストにはページ番号 (1、2...)が表示されます。

  • 項目のサブリストを表示する標準アクションの使用 (例: backgroundColor)。この機能には以下の条件があります:

    • スタイル付きテキストエリア (4D Write Pro エリア または マルチスタイル プロパティ付き 入力) が標準アクションのターゲットとしてフォーム内に存在する。
    • ドロップダウンリストに フォーカス可 設定されていない。実行時のドロップダウンリストは、背景色などの値の自動リストを表示します。この自動リストは、各項目が任意の標準アクションを割り当てられた選択リストを設定することで上書きすることもできます。

この機能は、階層型のドロップダウンリストでは使用できません。

サポートされる標準アクション​

ドロップダウンリストの標準アクションセレクターでは、以下の標準アクションが利用可能です。アクションの詳細と必要要件については標準アクション および4D Write Pro 標準アクション を参照してください。

gotoPage - fontSize - color - backgroundColor - textUnderlineStyle - textUnderlineColor - textLinethroughStyle - textLinethroughColor - textShadowOffset - textShadowColor - textTransform - dpi - zoom - userUnit - pageMode - pageSize - tabDecimalSeparator - pageOrientation - section/pageOrientation - columnCount - section/columnCount - columnSpacing - section/columnSpacing - columnRuleStyle - section/columnRuleStyle - columnRuleColor - section/columnRuleColor - columnRuleWidth - section/columnRuleWidth - bookmark - width - paragraph/width - image/width - column/width - image/height - row/height - minWidth - paragraph/minWidth - image/minWidth - minHeight - paragraph/minHeight - image/minHeight - margin - doc/margin - paragraph/margin - paragraph/inside/margin - paragraph/outside/margin - image/margin - section/margin - header/margin - footer/margin - table/margin - padding - doc/padding - paragraph/padding - paragraph/inside/padding - paragraph/outside/padding - image/padding - section/padding - header/padding - footer/padding - cell/padding - column/padding - doc/backgroundColor - paragraph/backgroundColor - image/backgroundColor - section/backgroundColor - header/backgroundColor - footer/backgroundColor - table/backgroundColor - row/backgroundColor - cell/backgroundColor - column/backgroundColor - backgroundPositionH - doc/backgroundPositionH - paragraph/backgroundPositionH - image/backgroundPositionH - section/backgroundPositionH - header/backgroundPositionH - footer/backgroundPositionH - table/backgroundPositionH - row/backgroundPositionH - cell/backgroundPositionH - column/backgroundPositionH - backgroundPositionV - doc/backgroundPositionV - paragraph/backgroundPositionV - image/backgroundPositionV - section/backgroundPositionV - header/backgroundPositionV - footer/backgroundPositionV - table/backgroundPositionV - row/backgroundPositionV - cell/backgroundPositionV - column/backgroundPositionV - backgroundRepeat - doc/backgroundRepeat - paragraph/backgroundRepeat - image/backgroundRepeat - section/backgroundRepeat - header/backgroundRepeat - footer/backgroundRepeat - table/backgroundRepeat - row/backgroundRepeat - cell/backgroundRepeat - column/backgroundRepeat - backgroundClip - doc/backgroundClip - paragraph/backgroundClip - image/backgroundClip - section/backgroundClip - header/backgroundClip - table/backgroundClip - row/backgroundClip - cell/backgroundClip - column/backgroundClip - backgroundOrigin - doc/backgroundOrigin - paragraph/backgroundOrigin - image/backgroundOrigin - section/backgroundOrigin - header/backgroundOrigin - footer/backgroundOrigin - table/backgroundOrigin - row/backgroundOrigin - cell/backgroundOrigin - column/backgroundOrigin - backgroundSizeH - doc/backgroundSizeH - paragraph/backgroundSizeH - image/backgroundSizeH - section/backgroundSizeH - header/backgroundSizeH - footer/backgroundSizeH - table/backgroundSizeH - row/backgroundSizeH - cell/backgroundSizeH - column/backgroundSizeH - backgroundSizeV - doc/backgroundSizeV - paragraph/backgroundSizeV - image/backgroundSizeV - section/backgroundSizeV - header/backgroundSizeV - footer/backgroundSizeV - table/backgroundSizeV - row/backgroundSizeV - cell/backgroundSizeV - column/backgroundSizev - borderStyle - doc/borderStyle - paragraph/borderStyle - paragraph/inside/borderStyle - paragraph/outside/borderStyle - image/borderStyle - section/borderStyle - header/borderStyle - footer/borderStyle - table/borderStyle - row/borderStyle - cell/borderStyle - column/borderStyle - borderColor - doc/borderColor - paragraph/borderColor - paragraph/inside/borderColor - paragraph/outside/borderColor - image/borderColor - section/borderColor - header/borderColor - footer/borderColor - table/borderColor - row/borderColor - cell/borderColor - column/borderColor - borderWidth- doc/borderWidth - paragraph/borderWidth - paragraph/inside/borderWidth - paragraph/outside/borderWidth - image/borderWidth - section/borderWidth - header/borderWidth - footer/borderWidth - table/borderWidth - row/borderWidth - cell/borderWidth - column/borderWidth - borderRadius - doc/borderRadius - paragraph/borderRadius - image/borderRadius - section/borderRadius - header/borderRadius - footer/borderRadius - direction - textAlign - lineHeight - listStyleType - listStartNumber - listNumberFormat - textIndent - verticalAlign - image/verticalAlign - cell/verticalAlign - column/verticalAlign - tableAlign - table/tableAlign - emptyDatasource - table/emptyDatasource - styleSheet - paragraph/styleSheet - image/styleSheet - newLineStyleSheet - anchorLayout - anchorHorizontalAlign - anchorVerticalAlign - anchorOrigin - anchorSection - anchorPage - image/displayMode - backgroundDisplayMode - doc/backgroundDisplayMode - paragraph/backgroundDisplayMode - image/backgroundDisplayMode - section/backgroundDisplayMode - header/backgroundDisplayMode - footer/backgroundDisplayMode - table/backgroundDisplayMode - row/backgroundDisplayMode - cell/backgroundDisplayMode - column/backgroundDisplayMode - formulaHighlight - formulaHighlightColor - headerRowCount

注

リストの自動テキスト書式設定に関しては、階層ドロップダウンリストの使用可能エリア、フォーカス要件、および制約については標準アクションの使用 を参照してください。テキスト書式設定ターゲットエリアとフォーカス要件は、gotoPage に関しては適用されません。

個別の選択リスト項目に割り当てられたアクションは、ドロップダウンリストに割り当てられたアクションとは異なります。

詳細については標準アクション互換性表 を参照してください。

プロパティ一覧​

タイプ - オブジェクト名 - 変数あるいは式 - 式の型 - 値を記憶 - CSSクラス - データタイプ (セレクションおよびコレクションリストボックス列) - データタイプ - 左 - 上 - 右 - 下 - 幅 - 高さ - 横方向サイズ変更 - 縦方向サイズ変更 - 選択リスト - フォーカス可 - 文字フォーマット - 日付フォーマット - 時間フォーマット - 表示状態 - レンダリングしない - フォント - フォントサイズ - 太字 - イタリック - 下線 - フォントカラー - 横揃え - ヘルプTips - 標準アクション

サポートされるイベント​

On After Edit - On After Keystroke - On Before Keystroke - On Begin Drag Over - On Clicked - On Data Change - On Drag Over - On Drop - On Header - On Load - On Mouse Enter - On Mouse Leave - On Mouse Move - On Printing Break - On Printing Detail - On Printing Footer - On Unload - On Validate