Add Selection Listener to the ListView : ListView « GUI « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » GUI » ListViewScreenshots 
Add Selection Listener to the ListView
Add Selection Listener to the ListView
 
Imports System
Imports System.Drawing
Imports System.Data
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
Imports System.Drawing.Printing

Public Class MainClass
    Shared Sub Main()
       Dim form1 As Form = New Form1()
       Application.Run(form1)
    End Sub
End Class



Public Class Form1
    Inherits System.Windows.Forms.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 NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    '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.
    Friend WithEvents lstFavorites As System.Windows.Forms.ListView
    Friend WithEvents hdrName As System.Windows.Forms.ColumnHeader
    Friend WithEvents hdrUrl As System.Windows.Forms.ColumnHeader
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.lstFavorites = New System.Windows.Forms.ListView()
        Me.hdrName = New System.Windows.Forms.ColumnHeader()
        Me.hdrUrl = New System.Windows.Forms.ColumnHeader()
        Me.SuspendLayout()
        '
        'lstFavorites
        '
        Me.lstFavorites.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom_
                    Or System.Windows.Forms.AnchorStyles.Left_
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.lstFavorites.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.hdrName, Me.hdrUrl})
        Me.lstFavorites.Location = New System.Drawing.Point(88)
        Me.lstFavorites.Name = "lstFavorites"
        Me.lstFavorites.Size = New System.Drawing.Size(504216)
        Me.lstFavorites.TabIndex = 2
        Me.lstFavorites.View = System.Windows.Forms.View.Details
        '
        'hdrName
        '
        Me.hdrName.Text = "Name"
        Me.hdrName.Width = 250
        '
        'hdrUrl
        '
        Me.hdrUrl.Text = "URL"
        Me.hdrUrl.Width = 250
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(520261)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lstFavorites})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Dim item As New YourListViewItem("First Item")
        lstFavorites.Items.Add(item)

        If lstFavorites.Items.Count = Then
             item.Selected = True
         End If
    End Sub


    Private Sub lstFavorites_Click(ByVal sender As Object, ByVal e As System.EventArgsHandles lstFavorites.Click
        Dim item As YourListViewItem
        For Each item In lstFavorites.Items
            If item.Selected = True Then
                MessageBox.Show(item.ItemName)
                Exit For
            End If
        Next
    End Sub

End Class


Public Class YourListViewItem
    Inherits ListViewItem
    Public ItemName As String

    Public Sub New(ByVal i As String)

        ItemName = i

        Text = i
        SubItems.Add("Sub " & i)

    End Sub


End Class

           
         
  
Related examples in the same category
1.ListView Custom sortListView Custom sort
2.Build ListView at run time: update title column textBuild ListView at run time: update title column text
3.Construct ListView at run time: build structure and insert recordsConstruct ListView at run time: build structure and insert records
4.Fill XML data into ListView and add column to ListView at run timeFill XML data into ListView and add column to ListView at run time
5.Large Icon and small Icon for ListView
6.Add Customized Item to ListViewAdd Customized Item to ListView
7.Add Items to ListViewAdd Items to ListView
8.Displaying directories and their contents in ListViewDisplaying directories and their contents in ListView
9.Set ListView header and fill dataSet ListView header and fill data
10.Drag and Drop Explorer
11.ListView DataReader
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.