1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
Imports System
Imports System.IO
Public Class Form2
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
' Disable automatic sorting to enable manual sorting.
Me.ListView1.Sorting = SortOrder.None
Me.ListView1.View = View.Details
' Add 4 columns and set their text.
Me.ListView1.Columns.Add(New ColumnHeader)
Me.ListView1.Columns(0).Text = "Produit "
Me.ListView1.Columns(0).Width = 100
ListView1.Columns.Add(New ColumnHeader)
ListView1.Columns(1).Text = "Categorie "
ListView1.Columns.Add(New ColumnHeader)
ListView1.Columns(2).Text = "Numero "
ListView1.Columns.Add(New ColumnHeader)
ListView1.Columns(3).Text = "Prix "
End Sub
Private Sub btnLoadItems_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadItems.Click
' Cree les ListViewItems .
Dim listViewItem1 As New ListViewItem(New String() {"Produit1", "Cat1", "11", "2050.00"}, -1, Color.Empty, Color.Yellow, Nothing)
Dim listViewItem2 As New ListViewItem(New String() {"Produit2", "Cat2", "12", "2275.15"}, -1, Color.Empty, Color.Red, New Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, CType(0, System.Byte)))
Dim listViewItem3 As New ListViewItem(New String() {"Produit3", "Cat3", "13", "1945.35"}, -1, Color.Empty, Color.Lime, Nothing)
Dim listViewItem4 As New ListViewItem(New String() {"Produit4", "Cat4", "14", "1754.02"}, -1, Color.Empty, Color.FromArgb(CType(192, System.Byte), CType(128, System.Byte), CType(156, System.Byte)), Nothing)
'Add Items
Me.ListView1.Items.AddRange(New ListViewItem() {listViewItem1, listViewItem2, listViewItem3, listViewItem4})
' Set the location and size of the ListView control.
Me.ListView1.Name = "listView1"
Me.ListView1.TabIndex = 0
' Enable editing of the items in the ListView.
Me.ListView1.LabelEdit = True
Me.ListView1.MultiSelect = True
Me.ListView1.FullRowSelect = True
End Sub
Private Sub btnSaveText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveText.Click
SaveText()
End Sub
Private Sub SaveText()
Dim reponse As DialogResult
SaveFileDialog1.FileName = "*.*"
SaveFileDialog1.Filter = "Fichiers Text (*.txt)|*.txt|Fichier HTML (*.html)|*.html|Fichier HTM (*.htm)|*.htm|Fichiers CSV (*.CSV)|*.CSV"
reponse = SaveFileDialog1.ShowDialog()
If reponse = DialogResult.OK Then
Using toto As StreamWriter = New StreamWriter(SaveFileDialog1.FileName)
' Add some text to the file.
toto.Write("This is the ")
toto.WriteLine("header for the file.")
toto.WriteLine("-------------------")
' Arbitrary objects can also be written to the file.
toto.Write("The date is: ")
toto.WriteLine(DateTime.Now)
Dim liste As ListView.ListViewItemCollection = ListView1.Items
For Each item As ListViewItem In liste
For Each subItem As ListViewItem.ListViewSubItem In item.SubItems
toto.Write(subItem.Text & "-")
Next
toto.WriteLine()
Next
toto.Close()
End Using
'chemin_fichier = SFD1.FileName
End If
End Sub
End Class |
Partager