Torna al Thread
Dim thisConnection As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbGipExpress.mdf;Integrated Security=True;User Instance=True")
Dim sql As String = "SELECT COMUNE, CAP, [PREFISSO TEL], [COD NAZIONALE], [COD ISTAT] FROM dbCOMUNI ORDER BY COMUNE"
Dim thisCommand As New SqlClient.SqlCommand(sql, thisConnection)
' Set the view to show details.
ListView1.View = View.Details
' Allow the user to edit item text.
ListView1.LabelEdit = True
' Allow the user to rearrange columns.
ListView1.AllowColumnReorder = True
' Display check boxes.
ListView1.CheckBoxes = True
' Select the item and subitems when selection is made.
ListView1.FullRowSelect = True
' Display grid lines.
ListView1.GridLines = True
' Sort the items in the list in ascending order.
ListView1.Sorting = SortOrder.Ascending
Try
thisConnection.Open()
Dim thisReader As SqlClient.SqlDataReader = thisCommand.ExecuteReader()
While (thisReader.Read())
Dim item As New ListViewItem(thisReader.Item(0).ToString, 0)
item.SubItems.Add(thisReader.Item(1).ToString)
item.SubItems.Add(thisReader.Item(2).ToString)
item.SubItems.Add(thisReader.Item(3).ToString)
item.SubItems.Add(thisReader.Item(4).ToString)
ListView1.Items.AddRange(New ListViewItem() {item})
End While
ListView1.Columns.Add("COMUNE", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("CAP", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("PREFISSO TEL", -2, HorizontalAlignment.Right)
ListView1.Columns.Add("COD NAZIONALE", -2, HorizontalAlignment.Center)
ListView1.Columns.Add("COD ISTAT", -2, HorizontalAlignment.Center)
Dim imageListSmall As New ImageList()
Dim imageListLarge As New ImageList()
' Initialize the ImageList objects with bitmaps.
imageListSmall.Images.Add(Bitmap.FromFile("C:\Favorites Folder white s.png"))
imageListSmall.Images.Add(Bitmap.FromFile("C:\Favorites Folder white.png"))
imageListLarge.Images.Add(Bitmap.FromFile("C:\Favorites Folder black s.png"))
imageListLarge.Images.Add(Bitmap.FromFile("C:\Favorites Folder black.png"))
'Assign the ImageList objects to the ListView.
ListView1.LargeImageList = imageListLarge
ListView1.SmallImageList = imageListSmall
Catch ex As SqlClient.SqlException
MsgBox("Error: " & ex.ToString())
Finally
thisConnection.Close()
End Try