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 88 89
|
Public Class Form1
Private ListPersons As List(Of Person)
Private p As Person
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ListPersons = New List(Of Person)
Dim rnd As Random = New Random
For i As Integer = 0 To 9
Me.p = New Person("Paul" & (i + 1).ToString, "Michel" & (i + 1).ToString, Date.Now, rnd.NextDouble * 1000)
Me.ListPersons.Add(p)
Next
Me.ListBox1.DataSource = Me.ListPersons
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Me.ListPersons IsNot Nothing Then
For Each p As Person In Me.ListPersons
Me.ListBox2.Items.Add(p.ToString)
Next
End If
End Sub
End Class
Class Person
Public Sub New(ByVal fn As String, ByVal ln As String, ByVal bd As Date, ByVal ac As Decimal)
m_FName = fn
m_LName = ln
m_Account = ac
m_BirthDate = bd
End Sub
' Expose a custom type from a bound property
Private m_FName As String
Public Property FName() As String
Get
Return m_FName
End Get
Set(ByVal value As String)
m_FName = value
End Set
End Property
Private m_LName As String
Public Property LName() As String
Get
Return m_LName
End Get
Set(ByVal value As String)
m_LName = value
End Set
End Property
Private m_BirthDate As Date
Public Property BirthDate() As Date
Get
Return m_BirthDate
End Get
Set(ByVal value As Date)
m_BirthDate = value
End Set
End Property
Private m_Account As Decimal
Public Property Account() As Decimal
Get
Return m_Account
End Get
Set(ByVal value As Decimal)
m_Account = value
End Set
End Property
'note que les espaces inseres avant et apres le pt-virgule
'dans la chaine de formatage compte
Public Overrides Function ToString() As String
Return String.Format("Nom :{0} ; Prenom : {1}; Compte : {2} ; DateNaissance : {3}", Me.LName, _
Me.LName, Me.Account, Me.BirthDate.ToShortDateString)
End Function
End Class |
Partager