Selected 屬性

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

expandtri全部顯示

使用 Visual Basic 中的 Selected 屬性可以確定列表框中的項(xiàng)目是否已選定。Long 型,可讀寫(xiě)。

expression.Selected(lRow)

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

lRow      必需,Long 型。列表框中的項(xiàng)目。第一項(xiàng)用零 (0) 表示,第二項(xiàng)用一 (1) 表示,依此類(lèi)推。

說(shuō)明

Selected 屬性是一個(gè)從零開(kāi)始的數(shù)組,該數(shù)組包含了列表框中每個(gè)項(xiàng)目的選擇狀態(tài)。

設(shè)置

說(shuō)明

True

選定列表框項(xiàng)目。

False

未選定列表框項(xiàng)目。

 

注釋  使用 Visual Basic 可以獲得或設(shè)置 Selected 屬性。

該屬性只在程序運(yùn)行時(shí)可用。

當(dāng)列表框控件的 MultiSelect 屬性設(shè)為“無(wú)”時(shí),只有一個(gè)項(xiàng)目的 Selected 屬性能夠設(shè)為 True。當(dāng)列表框控件的 MultiSelect 屬性設(shè)為“簡(jiǎn)單”或“展開(kāi)的”時(shí),任何項(xiàng)目的 Selected 屬性都可以設(shè)為 True。一個(gè)與字段綁定的多重選擇列表框?qū)⒂幸粋€(gè)始終等于 NullValue 屬性??梢允褂?Selected 屬性或 ItemsSelected 集合來(lái)檢索關(guān)于項(xiàng)目選擇情況的信息。

在 Visual Basic 中使用 Selected 屬性,可以從列表框中選擇項(xiàng)目。例如,下面的表達(dá)式將選擇列表中的第五項(xiàng)。

Me!Listbox.Selected(4) = True

示例

下面的示例使用 Selected 屬性將所選項(xiàng)目從 lstSource 列表框移到 lstDestination 列表框。其中 lstDestination 列表框的“行來(lái)源類(lèi)型”屬性設(shè)置為“值列表”,控件的“行來(lái)源”屬性由在 lstSource 控件中選定的所有項(xiàng)目決定。lstSource 列表框的“多重選擇”屬性設(shè)置為“展開(kāi)的”。CopySelected () 過(guò)程由 cmdCopyItem 命令按鈕調(diào)用。

Private Sub cmdCopyItem_Click()

    CopySelected Me

End Sub

Public Sub CopySelected(ByRef frm As Form)

    Dim ctlSource As Control

    Dim ctlDest As Control

    Dim strItems As String

    Dim intCurrentRow As Integer

    Set ctlSource = frm!lstSource

    Set ctlDest = frm!lstDestination

    For intCurrentRow = 0 To ctlSource.ListCount - 1

        If ctlSource.Selected(intCurrentRow) Then

            strItems = strItems & ctlSource.Column(0, _

                 intCurrentRow) & ";"

        End If

    Next intCurrentRow

    ' Reset destination control's RowSource property.

    ctlDest.RowSource = ""

    ctlDest.RowSource = strItems

    Set ctlSource = Nothing

    Set ctlDest = Nothing

End Sub