数据

The Data tab page allows you to assign a data source to the selected control.

要访问此命令...

Open context menu of a selected form element - choose Control - Data tab.

Open Form Controls toolbar or Form Design toolbar, click Control icon - Data tab.


批注图标

For forms with database links, the associated database is defined in the Form Properties. You will find the functions for this on the Data tab page.


The possible settings of the Data tab page of a control depend on the respective control. You will only see the options that are available for the current control and context.
The following fields are available:

列表内容

对于数据库窗体,为窗体元素的列表内容指定数据源。此字段也可用来为未连接数据库的文档定义值列表。

就数据库窗体而言,数据源确定列表框或组合框的条目。根据选定的类型,可以在列表内容中选择不同的数据源,只要数据库中存在这些对象。列表内容的类型中选定类型的所有可用数据库对象都可以在这里找到。如果选择“值列表”选项作为类型,则数据库窗体中可以使用引用。如果控件的显示由 SQL 命令控制,则在此输入 SQL 语句。

SQL 命令示例:

对于列表框, SQL 命令的表述形式如下:

SELECT Field1, Field2 FROM Table (从表格中选择字段1、字段2),

此处“表格”是指数据在控制字段的列表中显示的表格(列表表格)。“字段 1”是确定窗体中的可见条目的数据字段,它的内容将在列表框中显示出来。“字段2”是窗体表格中的字段,如果选择了固定的字段=1的话,这个字段与窗体表格(数值表格)通过在数据字段中指定的字段相链接。

对于组合框, SQL 命令的表述形式如下:

SELECT Distinct field FROM table,

其中,"field" 是列表表格 "table" 中的数据字段,此表格的内容显示在组合框的列表中。

HTML 文档中的数值列表

对于 HTML 窗体,可以在列表内容中输入数值列表。选择列表内容的类型中的选项“数值列表”。在这里输入的数值不会显示在窗体中,它们的作用是为可见的条目指定值。列表内容中的条目对应于 HTML 标记 <OPTION VALUE=...>。

在传送列表框或组合框中选定条目的数据时,表单中显示的值的列表(通过常规选项卡的列表条目指定)和数值列表(通过数据选项卡的列表内容指定)均是要考虑的因素:如果数值列表 (<OPTION VALUE=...>) 中的选定位置上是(非空)文字,则传送该文字。否则,传送 (<OPTION>) 控制中显示的文字。

如果要使值列表含有空字符串,则在列表内容中的相应位置输入值 $$$empty$$$(注意大小写)。LibreOfficeDev 将此输入解释为空字符串,并将其指定到相应的列表条目。

如下的表格显示了 HTML、JavaScript 和以"ListBox1" 列表框为依据的 LibreOfficeDev 字段列表内容间的相互关系。其中“条目”是指表单中的一个可见的列表条目:

HTML 标记

JavaScript

控件值列表中的条目(列表内容)

传递数据

<OPTION>Item

不可能

""

可见列表条目 ("ListBox1=Item")。

<OPTION VALUE="Value">Item

ListBox1.options[0].value="Value"

"Value"

分配给列表条目的值 ("ListBox1=Wert")

<OPTION VALUE="">Item

ListBox1.options[0].value=""

"$$$empty$$$"

一个空字符串("ListBox1=")。


列表内容的类型

确定填充列表框和组合框中列表的数据。

如果使用“数值列表”选项,控件将显示常规选项卡中的列表条目字段包含的所有条目。对于数据库窗体,可以使用引用值(请参阅使用数值列表的引用一节)。

如果控件的内容来自数据库,可以使用其他选项确定数据源的类型。例如,可以选择表格或查询。

固定的字段

批注图标

如果在属性浏览器中删除固定的字段的内容,结果集的第一个字段用于显示和交换数据。


这个用于列表框的属性决定了,一个被链接的表格中的哪个数据字段会显示在窗体中。

如果窗体中的列表框将要显示链接到窗体表格的表格内容,则在列表内容的类型字段中定义显示是否取决于 SQL 命令或者是否访问(链接)表格。通过联结字段属性,可以使用索引来指定要将列表字段链接到查询或表格中的哪一个数据字段。

批注图标

属性固定的字段仅适用于需要访问多个表格的表单。如果表单仅基于一个表格,则可以直接在数据字段中指定需要在表单中显示的字段。但如果要在列表框中显示表格中的数据,并且该表格通过公用数据字段链接到当前表格,则可以通过属性固定的字段来定义链接的数据字段。


如果在列表内容的类型中选择“Sql”,SQL 命令将确定要指定的索引。示例:如果在列表内容下指定 SQL 命令,例如“SELECT Field1, Field2 FROM tablename”,将引用以下表格:

固定的字段

链接

-1

The index of the selected entry in the list is linked to the field specified under Data field.

{空} 或者 0

数据库字段"字段1"与在数据字段里指定的字段相链接。

1

数据库字段“字段 2”与在数据字段中指定的字段相链接。


如果在列表内容的类型中选择“表格”,将由表格结构定义要指定的索引。示例:如果在列表内容中选择数据库表格,则引用以下表格:

固定的字段

链接

-1

The index of the selected entry in the list is linked to the field specified under Data field.

{空} 或者 0

表格的第 1 栏与在数据字段里指定的字段相链接。

1

表格第 2 栏与在数据字段中指定的字段相链接。

2

表格第 3 列与在数据字段中指定的字段相链接。


建议使用筛选

While designing your form, you can set the "Filter proposal" property for each text box in the Data tab of the corresponding Properties dialog. In subsequent searches in the filter mode, you can select from all information contained in these fields. The field content can then be selected using the AutoComplete function. Note, however, that this function requires a greater amount of memory space and time, especially when used in large databases and should therefore be used sparingly.

引用值(关)

Check boxes and radio buttons in spreadsheets can be bound to cells in the current document. If the control is enabled, the value you enter in Reference value (on) is copied to the cell. If the control is disabled, the value from Reference value (off) is copied to the cell.

引用值(打开)

您能为选项按钮和复选框指定引用值。当发送 Web 表单时,引用值将被提交到服务器。在数据库窗体中,此处输入的值将被写入到指定给控件字段的数据库中。

Web 表单引用值

当您设计了一个 Web 表单并向服务器传送控件的状态信息时,引用值非常有用。当控件被用户单击时,相应的引用值会发送到服务器。

例如,您有两个控制字段 -“女性”和“男性”选项,并且分别给它们指定引用值 "1" 和 "2"。当用户单击“女性”字段时,会传送数值 "1",当单击“男性”字段时,会传送数值 "2"。

数据库表格的引用值

在数据库表格中您也可以用引用值标记出一个选项框或复选框的状态,并把这个引用值存入数据库。比如:如果您给一个组的 3 个选项“工作中”、“完成”和“重复样式”各分配了一个引用值 "ToDo"、"OK" 和 "WV",那么当您点击每个选项时,这些引用值就显示在数据库中。

数据字段

对于数据库窗体,可以将控制与数据字段进行链接。

有以下几种可能:

  1. 第一种情况:表单中只有一个表格。

    数据字段中,指定要显示其内容的数据源表格的字段。

  2. 第二种情况:控制属于一个由 SQL 查询建立的子表单。

    数据字段中,指定要显示其内容的 SQL 语句字段。

  1. 第三种情况:组合框

    在组合框里,您在数据字段中指定当前窗体表格的字段,由用户输入或选中的值将保存在该字段中。在组合框的列表中显示的数值由在列表内容中输入的 SQL 语句确定。

  2. 第四种情况:列表框

    数据源表格中本身不含要显示的数据,而是含有一个表格,该表格通过公用数据字段链接到数据源表格。

    要在列表框中显示与当前数据源表格相连的表格中的数据,请在数据字段中指定列表框内容所引用的数据源表格字段,或者指定控制表单中数据显示的数据库字段。如果两个表格可以通过公用数据字段相连,则此数据字段提供到另一个表格的链接。数据字段通常存储了明确的标识码。其内容显示在表单中的数据字段由列表内容中的 SQL 语句指定。

带有引用的列表框。既可以在链接的表格中通过 SQL 语句来实现这个功能(第4种情况),也可以通过数值列表来达到这个目的:

通过链接表格引用(SQL 语句)

要在列表框中显示数据库表格中的数据,而该数据库表格通过公用数据字段与表单所依据的表格相连,则需要在数据字段中指定表单表格的链接字段。

如果在列表内容字段的列表内容的类型中选择 "sql" 或 "sql [Native]",则链接将通过 SQL Select 创建。例如,如果 "Orders" 表格被链接到当前表单控制,数据库中的 "Customers" 表格被链接到 "Orders" 表格,则可以使用以下 SQL 语句:

SELECT CustomerName, CustomerNo FROM Customers,

其中,"CustomerName" 是链接的 "Customers" 表格的数据字段,"CustomerNo" 是 "Customers" 表格的字段,该表格与数据字段下指定的 "Orders" 表单表格的字段相链接。

使用值列表的引用

在列表框中您可以使用数值列表,这是定义引用值的列表。这样,表单中的控制字段不再直接显示数据库字段的内容,而是显示通过数值列表指定的数值。

如果使用数值列表的引用值,则表单中不会显示数据字段中指定的数据字段内容,而是显示指定的数值。如果在数据选项卡的列表内容的类型中选择“数值列表”,并在列表条目(在常规选项卡中) 中为表单中可见的列表条目指定了引用值,则会将这些引用值与给定数据字段的数据内容进行比较。如果引用值与数据字段的内容相符,表单中将显示相关的列表条目。

源单元格区域

输入一个包含电子表格中列表框或组合框条目的单元格区域。 如果输入区域包含多列,则只有最左侧一列的内容用来填充控件。

空白字符是 NULL

Defines how an empty string input should be handled. If set to "Yes", an input string of length zero will be treated as a value NULL. If set to "No", any input will be treated as-is without any conversion.

An empty string is a string of length zero (""). Normally, a value NULL is not the same as an empty string. In general, a term NULL is used to denote an undefined value, an unknown value, or "no value has been entered yet."

数据库系统各有不同,它们可能使用不同的方法处理 NULL 值。请参阅您使用的数据库的文档说明。

链接单元格的内容

选择列表框与电子表格中的链接单元格之间的链接模式

  1. Linked contents: Synchronize the text contents of the selected list box entry with the cell contents. Select "The selected entry".

  2. Linked selection position: The position of the single selected item in the list box is synchronized with the numerical value in the cell. Select "Position of the selected entry".

链接的单元格

指定一个到电子表格的链接单元格的引用。控件的有效状态或内容链接到单元格的内容。以下表格列出了控件及其对应的链接类型:

带有链接单元格的复选框

操作

结果

Select the check box:

TRUE is entered into the linked cell.

Deselect the check box:

FALSE is entered into the linked cell.

Tri-state check box is set to "undetermined" state:

#NV is entered into the linked cell.

Enter a number or a formula that returns a number in the linked cell:

If entered value is TRUE or not 0: Check box is selected.
If entered value is FALSE or 0: Check box is deselected.

Clear the linked cell, or enter text, or enter a formula that returns text or an error:

如果是三态复选框则设为“不确定”状态,否则取消选中复选框。

Select the box. The Reference value box contains text:

The text from the Reference value box is copied to the cell.

Deselect the box. The Reference value box contains text:

系统将空字符串复制到单元格中。

The Reference value box contains text. Enter the same text into the cell:

选中复选框

The Reference value box contains text. Enter another text into the cell:

取消选中复选框。


带有链接单元格的选项按钮(单选按钮)

操作

结果

Select the option button:

TRUE is entered into the linked cell.

Option button is deselected by selecting another option button:

FALSE is entered into the linked cell.

Enter a number or a formula that returns a number in the linked cell:

If entered value is TRUE or not 0: Option button is selected.
If entered value is FALSE or 0: Option button is deselected.

Clear the linked cell, or enter text, or enter a formula that returns text or an error:

Option button is deselected.

Click the option button. The Reference value box contains text:

The text from the Reference value box is copied to the cell.

Click another option button of the same group. The Reference value box contains text:

系统将空字符串复制到单元格中。

The Reference value box contains text. Enter the same text into the cell:

选中选项按钮。

The Reference value box contains text. Enter another text into the cell:

清除选项按钮。


带有链接单元格的文字框

操作

结果

Enter text into the text box:

Text is copied into the linked cell.

Clear the text box:

Linked cell is cleared.

Enter text or a number in the linked cell:

Text or number is copied into the text box.

Enter a formula into the linked cell:

Formula result is copied into the text box.

Clear the linked cell:

Text box is cleared.


带有链接单元格的数字字段和格式化字段

操作

结果

Enter a number into the field:

Number is copied into the linked cell.

Clear the field:

Value 0 is set in the linked cell.

Enter a number or a formula that returns a number in the linked cell:

Number is copied into the field.

Clear the linked cell, or enter text, or enter a formula that returns text or an error:

Value 0 is set in the field.


带有链接单元格的列表框

列表框支持两种不同的链接模式,请参阅属性“链接的单元格内容”。

  1. Linked contents: Synchronize the text contents of the selected list box entry with the cell contents.

  2. Linked selection position: The position of the single selected item in the list box is synchronized with the numerical value in the cell.

操作

结果

Select a single list item:

内容已链接:将条目的文本复制到链接的单元格。

Selection is linked: Position of the selected item is copied into the linked cell.
For example, if the third item is selected, the number 3 will be copied.

Select several list items:

#NV is entered into the linked cell.

Deselect all list items:

Contents are linked: Linked cell is cleared.

Selection is linked: Value 0 is entered in the linked cell.

Enter text or a number into the linked cell:

Contents are linked: Find and select an equal list item.

Selection is linked: The list item at the specified position (starting with 1 for the first item) is selected. If not found, all items are deselected.

Enter a formula into the linked cell:

Find and select a list item that matches the formula result and link mode.

Clear the linked cell:

Deselect all items in the list box.

Change the contents of the list source range:

根据所作修改,更新列表框项。保留选中项,这将导致链接的单元格的更新。


带有链接单元格的组合框

操作

结果

Enter text into the edit field of the combo box, or select an entry from the drop-down list:

Text is copied into the linked cell.

Clear the edit field of the combo box:

Linked cell is cleared.

Enter text or a number into the linked cell:

Text or number is copied into the edit field of the combo box.

Enter a formula into the linked cell:

Formula result is copied into the edit field of the combo box.

Clear the linked cell:

Edit field of the combo box is cleared.

Change the contents of the list source range:

根据所作修改,更新下拉列表项。组合框的编辑字段和链接单元格不会改变。