ColumnCount 屬性

此頁(yè)沒(méi)有內(nèi)容條目
內(nèi)容

expandtri全部顯示

使用 ColumnCount 屬性可以指定列表框中或組合框的列表框部分所顯示的數(shù),或者送往圖表控件未綁定對(duì)象框OLE 對(duì)象中的列數(shù)。

expression.ColumnCount

expression     必需。返回“應(yīng)用于”列表中的一個(gè)對(duì)象的表達(dá)式。

設(shè)置

ColumnCount 屬性值是一個(gè)從 1 到查詢SQL 語(yǔ)句字段最大數(shù)目或值列表中值的最大數(shù)目之間的整數(shù),由控件RowSource 屬性指定。

使用控件的屬性表、Visual Basic,可以設(shè)置 ColumnCount 屬性。

對(duì)于表字段,可以在表“設(shè)計(jì)”視圖中“字段屬性”部分的“查閱”選項(xiàng)卡上,對(duì)將 DisplayControl 屬性設(shè)為“組合框”或“列表框”的字段設(shè)置該屬性

blueup提示

ColumnCount

說(shuō)明

例如,如果將“雇員”窗體上列表框的 ColumnCount 屬性設(shè)為 3,則一列可以顯示姓氏,另一列可以顯示名字,第三列可以顯示雇員 ID 號(hào)。

組合框或列表框可以有很多列。如果控件的 RowSource 屬性包含表、查詢或 SQL 語(yǔ)句的名稱,則組合框或列表框?qū)淖蟮接绎@示那一數(shù)據(jù)源中的字段,顯示的數(shù)目由 ColumnCount 屬性來(lái)指定。

若要顯示字段的不同組合,請(qǐng)為 RowSource 屬性創(chuàng)建一個(gè)新的查詢或新的 SQL 語(yǔ)句,并指定所需的字段和順序。

如果 RowSource 屬性中含有值的列表(RowSourceType 屬性設(shè)為“值列表”),則這些值會(huì)以其在 RowSource 屬性中列出的順序放在組合框或列表框的行和列中。例如,如果 RowSource 屬性含有一個(gè)“紅;綠;藍(lán);黃”列表,并且 ColumnCount 屬性設(shè)為 2,則組合框或列表框的第一行將包括第一列的“紅”和第二列的“綠”,第二行將包括第一列的“藍(lán)”和第二列的“黃”。

可以使用 ColumnWidths 屬性來(lái)設(shè)置控件中顯示的列的寬度,或者用于隱藏列。

示例

以下示例使用 Column 屬性和 ColumnCount 屬性來(lái)打印列表框中選定的值:

Public Sub Read_ListBox()

    Dim intNumColumns As Integer

    Dim intI As Integer

    Dim frmCust As Form

    Set frmCust = Forms!frmCustomers

    If frmCust!lstCustomerNames.ItemsSelected.Count > 0 Then

        ' Any selection?

        intNumColumns = frmCust!lstCustomerNames.ColumnCount

        Debug.Print "The list box contains "; intNumColumns; _

            IIf(intNumColumns = 1, " column", " columns"); _

             " of data."

        Debug.Print "The current selection contains:"

        For intI = 0 To intNumColumns - 1

            ' Print column data.

            Debug.Print frmCust!lstCustomerNames.Column(intI)

        Next intI

    Else

        Debug.Print "You haven't selected an entry in the " _

            & "list box."

    End If

    Set frmCust = Nothing

End Sub