ComboBox.ColumnWidths 屬性 (Access)ComboBox.ColumnWidths property (Access)

您可以使用 ColumnWidths 屬性指定多資料行下拉式方塊中每一資料行的寬度。You can use the ColumnWidths property to specify the width of each column in a multiple-column combo box. 可讀寫的 StringRead/write String.

語法Syntax

運算式欄寬expression.ColumnWidths

_運算式_代表**ComboBox** 物件的變數。expression A variable that represents a ComboBox object.

註解Remarks

ColumnWidths屬性包含值,指定每個欄的寬度以英吋或公分,根據地區的 [編號] 索引標籤上的 [度量單位系統] 方塊中選取的度量系統 (US 或公制)選項在 Windows [控制台] 對話方塊。The ColumnWidths property holds a value specifying the width of each column in inches or centimeters, depending on the measurement system (U.S. or Metric) selected in the Measurement system box on the Number tab of the Regional Options dialog box of the Windows Control Panel. 預設值為 1 英吋或 2.54 公分為單位。The default setting is 1 inch or 2.54 centimeters. ColumnWidths 屬性設定值必須介於 0 到 22 英吋 (55.87 公分) 值的清單方塊或下拉式方塊中的各欄。The ColumnWidths property setting must be a value from 0 to 22 inches (55.87 cm) for each column in the list box or combo box.

To separate your column entries, use semicolons (;) as list separators (or the list separator selected in the List separator box on the Number tab of the Regional Options dialog box).To separate your column entries, use semicolons (;) as list separators (or the list separator selected in the List separator box on the Number tab of the Regional Options dialog box).

寬度為 0 會隱藏資料行。A width of 0 hides a column. 任何或所有 ColumnWidths 屬性設定值可以都是空白的。Any or all of the ColumnWidths property settings can be blank. 您輸入一個以上的值不清單分隔字元來建立空白的設定。You create a blank setting by typing a list separator without a preceding value. 空白值將會自動地使 Microsoft Access 設定預設資料行寬,且該資料行寬的變化取決於資料行數和下拉式方塊或清單方塊的寬度。Blank values result in Microsoft Access automatically setting a default column width that varies depending on the number of columns and the width of the combo box or list box.

在下拉式方塊內,第一個看得見的資料行會顯示在控制項的文字方塊部分中。In a combo box, the first visible column is displayed in the text box portion of the control.

在 Visual Basic 中使用的字串運算式來設定資料行寬值以twip 為單位In Visual Basic, use a string expression to set the column width values in twips. 資料行寬是經由分號來分隔。Column widths are separated by semicolons. 若要指定不同的測量單位,請包括測量基準 (公分或英吋) 的單位。To specify a different unit of measurement, include the unit of measure (cm or in). 例如,下列字串運算式以公分指定三個資料行寬。For example, the following string expression specifies three column widths in centimeters.

"6 cm;0;6 cm"

您也可以使用此屬性隱藏一個或多個資料行。You can also use this property to hide one or more columns.

如果您將ColumnWidths屬性設定值保留空白,Access 會將每一欄的寬度設定為清單方塊或下拉式方塊除以資料行數目的整體寬度。If you leave the ColumnWidths property setting blank, Access sets the width of each column as the overall width of the list box or combo box divided by the number of columns.

如果您設定的資料行寬太寬,若要能完全顯示在下拉式方塊或清單方塊內,最右邊的欄會被隱藏而且會顯示水平捲軸。If the column widths that you set are too wide to be fully displayed within the combo box or list box, the rightmost columns are hidden and a horizontal scroll bar appears.

如果您指定某些資料行的寬度,但保留空白其他人的設定,Access 會將剩餘的寬度除以尚未指定寬度的欄數。If you specify the width for some columns but leave the setting for others blank, Access divides the remaining width by the number of columns for which you haven't specified a width. 資料行寬的最小值是 1,440 個 Twip (1 英吋)。The minimum calculated column width is 1,440 twips (1 inch).

例如,下列設定值套用於具有三資料行的 4 英吋清單方塊上。For example, the following settings are applied to a 4-inch list box with three columns.

設定Setting 描述Description
1.5 in;0;2.5 in 第一資料行是 1.5 英吋,第二資料行是隱藏的,第三資料行是 2.5 英吋。The first column is 1.5 inches, the second column is hidden, and the third column is 2.5 inches.
2 in;;2 in 第一資料行是 2 英吋,第二資料行是 1 英吋 (預設值),第三資料行是 2 英吋。The first column is 2 inches, the second column is 1 inch (default), and the third column is 2 inches.

因為第三資料行僅看得見一半,所以會顯示水平捲軸。Because only half of the third column is visible, a horizontal scroll bar appears.
(空白)(Blank) 三資料行寬度相同 (1.33英吋)。The three columns are the same width (1.33 inches).

注意

[!注意事項] 此屬性為不同於 ColumnWidth 屬性,指定使用者在資料工作表中指定的資料行的寬度。This property is different than the ColumnWidth property, which specifies the width of a specified column in a datasheet.

範例Example

下列範例會示範如何建立時顯示另一個繫結至一欄的下拉式方塊。The following example shows how to create a combo box that is bound to one column while displaying another. 設定 ColumnCount 的屬性為 2,即表示 cboDept 下拉式方塊會顯示由 RowSource 屬性所指定資料來源的前兩欄。Setting the ColumnCount property to 2 specifies that the cboDept combo box will display the first two columns of the data source specified by the RowSource property. 設定 BoundColumn 的屬性為 1 ,即表示當您檢查下拉式方塊的值時,會將儲存於第一欄的值傳回。Setting the BoundColumn property to 1 specifies that the value stored in the first column will be returned when you inspect the value of the combo box.

ColumnWidths屬性會指定兩個資料行的寬度。The ColumnWidths property specifies the width of the two columns. 藉由設定第一欄的寬度0in.,第一欄不會顯示在下拉式方塊。By setting the width of the first column to 0in., the first column is not displayed in the combo box.

Private Sub cboDept_Enter()
    With cboDept
        .RowSource = "SELECT * FROM tblDepartments ORDER BY Department"
        .ColumnCount = 2
        .BoundColumn = 1
        .ColumnWidths = "0in.;1in."
    End With
End Sub

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.