⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 LISTVIEW + DATABASE PROGRAMMING FUNCTIONS IN A NUTSHELL This solution contains a classLibrary projec
💻 VB
字号:
Imports System.Configuration
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 Nothing) Then
                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 GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader5 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader6 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader7 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader8 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader9 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader10 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader11 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents cmnuSelectText As System.Windows.Forms.MenuItem
    Friend WithEvents cmnuSelectNumeric As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.CheckBox1 = New System.Windows.Forms.CheckBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader4 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader5 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader6 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader7 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader8 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader9 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader10 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader11 = New System.Windows.Forms.ColumnHeader
        Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
        Me.cmnuSelectText = New System.Windows.Forms.MenuItem
        Me.cmnuSelectNumeric = New System.Windows.Forms.MenuItem
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.BackColor = System.Drawing.SystemColors.Control
        Me.GroupBox1.Controls.Add(Me.ListView1)
        Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Top
        Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(498, 224)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        '
        'ListView1
        '
        Me.ListView1.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4, Me.ColumnHeader5, Me.ColumnHeader6, Me.ColumnHeader7, Me.ColumnHeader8, Me.ColumnHeader9, Me.ColumnHeader10, Me.ColumnHeader11})
        Me.ListView1.ContextMenu = Me.ContextMenu1
        Me.ListView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.ListView1.Location = New System.Drawing.Point(3, 16)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(492, 205)
        Me.ListView1.TabIndex = 0
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(8, 232)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(80, 24)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Load Data"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(96, 232)
        Me.Button2.Name = "Button2"
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "Close Form"
        '
        'CheckBox1
        '
        Me.CheckBox1.Location = New System.Drawing.Point(352, 232)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.Size = New System.Drawing.Size(152, 24)
        Me.CheckBox1.TabIndex = 3
        Me.CheckBox1.Text = "Start coloring at odd row"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Gold
        Me.Label1.Location = New System.Drawing.Point(176, 232)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(168, 24)
        Me.Label1.TabIndex = 4
        '
        'ColumnHeader1
        '
        Me.ColumnHeader1.Text = "Customer ID"
        Me.ColumnHeader1.Width = 80
        '
        'ColumnHeader2
        '
        Me.ColumnHeader2.Text = "Company Name"
        Me.ColumnHeader2.Width = 130
        '
        'ColumnHeader3
        '
        Me.ColumnHeader3.Text = "Contact Name"
        Me.ColumnHeader3.Width = 130
        '
        'ColumnHeader4
        '
        Me.ColumnHeader4.Text = "Contact Title"
        Me.ColumnHeader4.Width = 130
        '
        'ColumnHeader5
        '
        Me.ColumnHeader5.Text = "Address"
        Me.ColumnHeader5.Width = 200
        '
        'ColumnHeader6
        '
        Me.ColumnHeader6.Text = "City"
        Me.ColumnHeader6.Width = 100
        '
        'ColumnHeader7
        '
        Me.ColumnHeader7.Text = "Region"
        '
        'ColumnHeader8
        '
        Me.ColumnHeader8.Text = "Postal Code"
        Me.ColumnHeader8.Width = 80
        '
        'ColumnHeader9
        '
        Me.ColumnHeader9.Text = "Country"
        Me.ColumnHeader9.Width = 100
        '
        'ColumnHeader10
        '
        Me.ColumnHeader10.Text = "Phone"
        Me.ColumnHeader10.Width = 100
        '
        'ColumnHeader11
        '
        Me.ColumnHeader11.Text = "Fax"
        Me.ColumnHeader11.Width = 100
        '
        'ContextMenu1
        '
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.cmnuSelectText, Me.cmnuSelectNumeric})
        '
        'cmnuSelectText
        '
        Me.cmnuSelectText.Index = 0
        Me.cmnuSelectText.Text = "Select A Text Item"
        '
        'cmnuSelectNumeric
        '
        Me.cmnuSelectNumeric.Index = 1
        Me.cmnuSelectNumeric.Text = "Select A Numeric Item"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(498, 264)
        Me.ControlBox = False
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.CheckBox1)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.Text = "ListView Example"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'close the form and exit from the application
        Application.Exit()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cn As Data.OleDb.OleDbConnection
        Dim strCon, strAccessDbPath, strSql As String
        Dim blStartAtOddRow As Boolean
        Dim clr As Color

        'now create the path to the database
        strAccessDbPath = ConfigurationSettings.AppSettings("AccessDbPath")

        'now create the connection string
        strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                 "Data Source=" & strAccessDbPath

        cn = New Data.OleDb.OleDbConnection(strCon) 'the connection object
        strSql = "SELECT * FROM Customers ORDER BY CustomerID" 'the sql statement

        'now create an object of the listviewfunction dll file
        'ListViewFunctions- is the namespace of the class library project
        Dim lvfncobj As New ListViewFunctions.lvFunc
        Try
            'set the start at odd row options value
            If Me.CheckBox1.Checked Then
                blStartAtOddRow = True
            Else
                blStartAtOddRow = False
            End If
            'set the color of alternative rows
            clr = Color.Orchid

            'now call the sub to fill up the listview
            lvfncobj.FillListView_MSA(strSql, cn, Me.ListView1, clr, blStartAtOddRow, True, Me.Label1)

        Catch ex As Exception
            lvfncobj.CustomExceptionMessage(ex)
        End Try

    End Sub

    Private Sub cmnuSelectText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmnuSelectText.Click
        Dim strRet As String
        Dim intColNo As Int16
        strRet = InputBox("Please enter the column number you want to get the value of : ", "Enter Column Number", 1)
        'validate the user input to make sure that the column number is numeric
        If Not strRet = "" Then
            If IsNumeric(strRet) Then intColNo = CInt(strRet)
        Else
            Exit Sub
        End If

        Dim myobj As New ListViewFunctions.lvFunc
        'call the function to get the text value
        MsgBox(myobj.SelectAnTextItemOfListView(Me.ListView1.SelectedItems, False, intColNo))
    End Sub

    Private Sub cmnuSelectNumeric_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmnuSelectNumeric.Click
        Dim strRet As String
        Dim intColNo, intRetVal As Int16
        strRet = InputBox("Please enter the column number you want to get the value of : ", "Enter Column Number", 1)
        'validate the user input to make sure that the column number is numeric
        If Not strRet = "" Then
            If IsNumeric(strRet) Then intColNo = CInt(strRet)
        Else
            Exit Sub
        End If

        Dim myobj As New ListViewFunctions.lvFunc
        'call the function to get the numeric value
        intRetVal = myobj.SelectAnNumericItemOfListView(Me.ListView1.SelectedItems, False, intColNo)
        If Not intRetVal = 0 Then MsgBox(intRetVal)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox(Me.ListView1.Items(0).SubItems.Count())
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -