ListView DataReader : 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 
ListView DataReader
  
Imports System.Data.SqlClient
Imports System.Windows.Forms
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class List
    Inherits System.Windows.Forms.Form

    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.cmdClear = New System.Windows.Forms.Button
        Me.cmdFill = New System.Windows.Forms.Button
        Me.lvOrders = New System.Windows.Forms.ListView
        Me.SuspendLayout()
        '
        Me.cmdClear.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cmdClear.Location = New System.Drawing.Point(206231)
        Me.cmdClear.Size = New System.Drawing.Size(8024)
        Me.cmdClear.TabIndex = 5
        Me.cmdClear.Text = "Clear List"
        '
        Me.cmdFill.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.cmdFill.Location = New System.Drawing.Point(10231)
        Me.cmdFill.Size = New System.Drawing.Size(8024)
        Me.cmdFill.TabIndex = 4
        Me.cmdFill.Text = "Fill List"
        '
        Me.lvOrders.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom_
                    Or System.Windows.Forms.AnchorStyles.Left_
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lvOrders.Location = New System.Drawing.Point(611)
        Me.lvOrders.Size = New System.Drawing.Size(280212)
        Me.lvOrders.TabIndex = 3
        Me.lvOrders.UseCompatibleStateImageBehavior = False
        Me.lvOrders.View = System.Windows.Forms.View.Details
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292266)
        Me.Controls.Add(Me.cmdClear)
        Me.Controls.Add(Me.cmdFill)
        Me.Controls.Add(Me.lvOrders)
        Me.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents cmdClear As System.Windows.Forms.Button
    Friend WithEvents cmdFill As System.Windows.Forms.Button
    Friend WithEvents lvOrders As System.Windows.Forms.ListView

    Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdClear.Click
        lvOrders.Clear()
    End Sub

    Private Sub cmdFill_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdFill.Click
        Dim Connect As String = "Data Source=localhost;Integrated Security=True;Initial Catalog=Northwind"
        Dim con As New SqlConnection(Connect)

        Dim SQLString As String = "SELECT * FROM Orders"
        Dim cmd As New SqlCommand(SQLString, con)

        con.Open()

        Dim reader As SqlDataReader = cmd.ExecuteReader()
        Dim As Integer
        For i = To reader.FieldCount - 1
            lvOrders.Columns.Add("Column " (i + 1).ToString, 100, _
             HorizontalAlignment.Left)
        Next

        Do While (reader.Read())
            Dim NewItem As New ListViewItem()
            NewItem.Text = reader(0)
            For i = To reader.FieldCount - 1
                If reader(iIs DBNull.Value Then
                    NewItem.SubItems.Add("")
                Else
                    NewItem.SubItems.Add(reader(i).ToString)
                End If
            Next i
            lvOrders.Items.Add(NewItem)
        Loop
        Dim Table As DataTable = reader.GetSchemaTable()
        For j As Integer = To Table.Rows.Count - 1
            lvOrders.Columns(j).Text = Table.Rows(j)("ColumnName")
        Next
        reader.Close()
        con.Close()
    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 Selection Listener to the ListViewAdd Selection Listener to the ListView
8.Add Items to ListViewAdd Items to ListView
9.Displaying directories and their contents in ListViewDisplaying directories and their contents in ListView
10.Set ListView header and fill dataSet ListView header and fill data
11.Drag and Drop Explorer
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.