本文整理匯總了VB.NET中System.Windows.Forms.ListView.CheckedItems屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET ListView.CheckedItems屬性的具體用法?VB.NET ListView.CheckedItems怎麽用?VB.NET ListView.CheckedItems使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Windows.Forms.ListView
的用法示例。
在下文中一共展示了ListView.CheckedItems屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: InitializeListView
Private Sub InitializeListView()
Me.ListView1 = New System.Windows.Forms.ListView
' Set properties such as BackColor, Location and Size
Me.ListView1.BackColor = System.Drawing.SystemColors.Control
Me.ListView1.Dock = System.Windows.Forms.DockStyle.Top
Me.ListView1.Location = New System.Drawing.Point(0, 0)
Me.ListView1.Size = New System.Drawing.Size(292, 130)
Me.ListView1.View = System.Windows.Forms.View.Details
Me.ListView1.HideSelection = False
' Allow user to select multiple items.
Me.ListView1.MultiSelect = True
' Show check boxes in the ListView.
Me.ListView1.CheckBoxes = True
'Set the column headers and populate the columns.
ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable
Dim columnHeader1 As New ColumnHeader
With columnHeader1
.Text = "Breakfast Choices"
.TextAlign = HorizontalAlignment.Left
.Width = 146
End With
Dim columnHeader2 As New ColumnHeader
With columnHeader2
.Text = "Price Each"
.TextAlign = HorizontalAlignment.Center
.Width = 142
End With
Me.ListView1.Columns.Add(columnHeader1)
Me.ListView1.Columns.Add(columnHeader2)
Dim foodList() As String = New String() {"Juice", "Coffee", _
"Cereal & Milk", "Fruit Plate", "Toast & Jelly", _
"Bagel & Cream Cheese"}
Dim foodPrice() As String = New String() {"1.09", "1.09", "2.19", _
"2.79", "2.09", "2.69"}
Dim count As Integer
' Members are added one at a time, so call BeginUpdate to ensure
' the list is painted only once, rather than as each list item is added.
ListView1.BeginUpdate()
For count = 0 To foodList.Length - 1
Dim listItem As New ListViewItem(foodList(count))
listItem.SubItems.Add(foodPrice(count))
ListView1.Items.Add(listItem)
Next
'Call EndUpdate when you finish adding items to the ListView.
ListView1.EndUpdate()
Me.Controls.Add(Me.ListView1)
End Sub
示例2: If
' Handles the ItemCheck event. The method loops through all the
' checked items and tallies a new price each time an item is
' checked or unchecked. It outputs the price to TextBox1.
Private Sub ListView1_ItemCheck2(ByVal sender As Object, _
ByVal e As System.Windows.Forms.ItemCheckEventArgs) _
Handles ListView1.ItemCheck
Dim item As ListViewItem
Dim price As Double = 0.0
Dim checkedItems As ListView.CheckedListViewItemCollection = _
ListView1.CheckedItems
For Each item In checkedItems
price += Double.Parse(item.SubItems(1).Text)
Next
If (e.CurrentValue = CheckState.Unchecked) Then
price += Double.Parse(Me.ListView1.Items(e.Index).SubItems(1).Text)
ElseIf (e.CurrentValue = CheckState.Checked) Then
price -= Double.Parse(Me.ListView1.Items(e.Index).SubItems(1).Text)
End If
' Output the price to TextBox1.
TextBox1.Text = CType(price, String)
End Sub