当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET ListView.SelectedItems属性代码示例

本文整理汇总了VB.NET中System.Windows.Forms.ListView.SelectedItems属性的典型用法代码示例。如果您正苦于以下问题:VB.NET ListView.SelectedItems属性的具体用法?VB.NET ListView.SelectedItems怎么用?VB.NET ListView.SelectedItems使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Windows.Forms.ListView的用法示例。


在下文中一共展示了ListView.SelectedItems属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: InitializeListView

' This method adds two columns to the ListView, setting the Text 
' and TextAlign, and Width properties of each ColumnHeader.  The 
' HeaderStyle property is set to NonClickable since the ColumnClick 
' event is not handled.  Finally the method adds ListViewItems and 
' SubItems to each column.
Private Sub InitializeListView()
    Me.ListView1 = New System.Windows.Forms.ListView
    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.Name = "ListView1"
    Me.ListView1.Size = New System.Drawing.Size(292, 130)
    Me.ListView1.TabIndex = 0
    Me.ListView1.View = System.Windows.Forms.View.Details
    Me.ListView1.MultiSelect = True
    Me.ListView1.HideSelection = False
    ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable
    Dim columnHeader1 As New ColumnHeader
    With columnHeader1
        .Text = "Breakfast Item"
        .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.49", "1.49", "1.49"}
    Dim count As Integer
    For count = 0 To foodList.Length - 1
        Dim listItem As New ListViewItem(foodList(count))
        listItem.SubItems.Add(foodPrice(count))
        ListView1.Items.Add(listItem)
    Next
    Me.Controls.Add(Me.ListView1)
End Sub
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:45,代码来源:ListView.SelectedItems

示例2: CType

' Uses the SelectedItems property to retrieve and tally the price 
' of the selected menu items.
Private Sub ListView1_SelectedIndexChanged_UsingItems _
    (ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles ListView1.SelectedIndexChanged

    Dim breakfast As ListView.SelectedListViewItemCollection = _
        Me.ListView1.SelectedItems
    Dim item As ListViewItem
    Dim price As Double = 0.0
    For Each item In breakfast
        price += Double.Parse(item.SubItems(1).Text)
    Next

    ' Output the price to TextBox1.
    TextBox1.Text = CType(price, String)
End Sub
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:17,代码来源:ListView.SelectedItems

示例3: MainClass

' 导入命名空间
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.IO

Public Class MainClass

   Shared Sub Main()
        Dim myform As Form = New FrmListView()
        Application.Run(myform)

   End Sub ' Main

End Class


Public Class FrmListView
   Inherits Form

#Region " Windows Form Designer generated code "

   Public Sub New()
      MyBase.New()

      'This call is required by the Windows Form Designer.
      InitializeComponent()

      'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
         If Not (components Is Nothing) Then
            components.Dispose()
         End If
      End If
      MyBase.Dispose(disposing)
   End Sub

   ' display labels for current location in directory tree
   Friend WithEvents lblCurrent As Label
   Friend WithEvents lblDisplay As Label

   ' displays contents of current directory
   Friend WithEvents lvwBrowser As ListView

   ' specifies images for file icons and folder icons
   Friend WithEvents ilsFileFolder As ImageList


   'Required by the Windows Form Designer
   Private components As System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
      Me.components = New System.ComponentModel.Container()
      Me.ilsFileFolder = New System.Windows.Forms.ImageList(Me.components)
      Me.lvwBrowser = New System.Windows.Forms.ListView()
      Me.lblCurrent = New System.Windows.Forms.Label()
      Me.lblDisplay = New System.Windows.Forms.Label()
      Me.SuspendLayout()
      '
      'ilsFileFolder
      '
      Me.ilsFileFolder.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
      Me.ilsFileFolder.ImageSize = New System.Drawing.Size(16, 16)
      Me.ilsFileFolder.TransparentColor = System.Drawing.Color.Transparent
      '
      'lvwBrowser
      '
      Me.lvwBrowser.Location = New System.Drawing.Point(16, 88)
      Me.lvwBrowser.Name = "lvwBrowser"
      Me.lvwBrowser.RightToLeft = System.Windows.Forms.RightToLeft.No
      Me.lvwBrowser.Size = New System.Drawing.Size(448, 232)
      Me.lvwBrowser.SmallImageList = Me.ilsFileFolder
      Me.lvwBrowser.TabIndex = 2
      Me.lvwBrowser.View = System.Windows.Forms.View.List
      '
      'lblCurrent
      '
      Me.lblCurrent.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.lblCurrent.ForeColor = System.Drawing.SystemColors.WindowText
      Me.lblCurrent.Location = New System.Drawing.Point(16, 16)
      Me.lblCurrent.Name = "lblCurrent"
      Me.lblCurrent.Size = New System.Drawing.Size(112, 23)
      Me.lblCurrent.TabIndex = 0
      Me.lblCurrent.Text = "Now in Directory:"
      '
      'lblDisplay
      '
      Me.lblDisplay.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.lblDisplay.ForeColor = System.Drawing.SystemColors.WindowText
      Me.lblDisplay.Location = New System.Drawing.Point(128, 16)
      Me.lblDisplay.Name = "lblDisplay"
      Me.lblDisplay.Size = New System.Drawing.Size(344, 56)
      Me.lblDisplay.TabIndex = 1
      '
      'FrmListView
      '
      Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
      Me.ClientSize = New System.Drawing.Size(488, 341)
      Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lvwBrowser, Me.lblDisplay, Me.lblCurrent})
      Me.Name = "FrmListView"
      Me.Text = "ListViewTest"
      Me.ResumeLayout(False)

   End Sub

#End Region

   Dim currentDirectory As String = Directory.GetCurrentDirectory()

   Private Sub lvwBrowser_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles lvwBrowser.Click
      If lvwBrowser.SelectedItems.Count <> 0 Then
         If lvwBrowser.Items(0).Selected Then

            Dim directoryObject As DirectoryInfo = _
               New DirectoryInfo(currentDirectory)

            If Not (directoryObject.Parent Is Nothing) Then
               LoadFilesInDirectory(directoryObject.Parent.FullName)
            End If
         Else
            Dim chosen As String = lvwBrowser.SelectedItems(0).Text
            If Directory.Exists(currentDirectory & "\" & chosen) Then
               If currentDirectory = "C:\" Then
                  LoadFilesInDirectory(currentDirectory & chosen)
               Else
                  LoadFilesInDirectory(currentDirectory & _
                     "\" & chosen)
               End If
            End If
         End If
         lblDisplay.Text = currentDirectory
      End If
   End Sub

   Public Sub LoadFilesInDirectory _
      (ByVal currentDirectoryValue As String)
      Try
         lvwBrowser.Items.Clear()
         lvwBrowser.Items.Add("Go Up One Level")
         currentDirectory = currentDirectoryValue
         Dim newCurrentDirectory As DirectoryInfo = _
            New DirectoryInfo(currentDirectory)
         Dim directoryArray As DirectoryInfo() = _
            newCurrentDirectory.GetDirectories()

         Dim fileArray As FileInfo() = _
            newCurrentDirectory.GetFiles()
         Dim dir As DirectoryInfo
         For Each dir In directoryArray
            Dim newDirectoryItem As ListViewItem = _
               lvwBrowser.Items.Add(dir.Name)
            newDirectoryItem.ImageIndex = 0
         Next
         Dim file As FileInfo
         For Each file In fileArray
            Dim newFileItem As ListViewItem = _
               lvwBrowser.Items.Add(file.Name)
            newFileItem.ImageIndex = 1    ' set file image
         Next
      Catch exception As UnauthorizedAccessException
         MessageBox.Show("Warning: Some files may " & _
            "not be visible due to " + "permission settings", _
            "Attention", 0, MessageBoxIcon.Warning)
      End Try

   End Sub ' LoadFilesInDirectory

   ' handle load event when Form displayed for first time
   Private Sub FrmListView_Load(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles MyBase.Load

      ' set image list
      Dim folderImage As Image = Image.FromFile("figure2.bmp")

      Dim fileImage As Image = Image.FromFile("figure2.bmp")

      ilsFileFolder.Images.Add(folderImage)
      ilsFileFolder.Images.Add(fileImage)

      ' load current directory into browserListView
      LoadFilesInDirectory(currentDirectory)
      lblDisplay.Text = currentDirectory
   End Sub ' FrmListView_Load

End Class
开发者ID:VB程序员,项目名称:System.Windows.Forms,代码行数:194,代码来源:ListView.SelectedItems


注:本文中的System.Windows.Forms.ListView.SelectedItems属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。