S
Shan1986
Guest
Hallo,
I have following code given by Karen. I am trying to understand classes. What i am trying to achieve here is following.
1. Add multiple email or phone Number to person contact
2. Display the selected person contact info in datagridview to see all emails and phone number of the selected person.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim people As New List(Of Person) From {
New Person With {
.Id = 1,
.FirstName = "Jim",
.LastName = "Smith",
.Contact = New Contact() With {
.ContactId = 10,
.PersonId = 1,
.Phone = "5555555555",
.Address = "123 Apple Lane",
.Email = "js@comcast.net",
.NickName = "XYZ"}},
New Person With {
.Id = 1,
.FirstName = "Jim",
.LastName = "Smith",
.Contact = New Contact() With {
.ContactId = 11,
.PersonId = 1,
.Phone = "666666666666",
.Address = "123 orange Lane",
.Email = "js@comcast.net",
.NickName = "SHANZ"}},
New Person With {
.Id = 2,
.FirstName = "Mary",
.LastName = "Bickmen",
.Contact = New Contact() With {
.ContactId = 20,
.PersonId = 2,
.Phone = "6666666666",
.Address = "33 Wyndmoor Lane",
.Email = "mb@gmail",
.NickName = "Hot apples"}}
}
ComboBox1.DataSource = people
ComboBox1.DisplayMember = "LastName"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim person = CType(ComboBox1.SelectedItem, Person)
Dim contact = person.Contact
Dim Get_Contact As New List(Of Contact)(contact)
Datagridview1.DataSource = Get_Contact
End Sub
End Class
Public Class Person
Public Property Id() As Integer
Public Property FirstName As String
Public Property LastName As String
Public Property Contact() As Contact
Public Overrides Function ToString() As String
Return FirstName
End Function
End Class
Public Class Contact
Public Property ContactId() As Integer
Public Property PersonId() As Integer
Public Property NickName As String
Public Property Email As String
Public Property Phone As String
Public Property Address As String
End Class
I tried somthing like this but it does not work.
Dim Get_Contact As New List(Of Contact)(contact)
Datagridview1.DataSource = Get_Contact
Thanks
Continue reading...
I have following code given by Karen. I am trying to understand classes. What i am trying to achieve here is following.
1. Add multiple email or phone Number to person contact
2. Display the selected person contact info in datagridview to see all emails and phone number of the selected person.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim people As New List(Of Person) From {
New Person With {
.Id = 1,
.FirstName = "Jim",
.LastName = "Smith",
.Contact = New Contact() With {
.ContactId = 10,
.PersonId = 1,
.Phone = "5555555555",
.Address = "123 Apple Lane",
.Email = "js@comcast.net",
.NickName = "XYZ"}},
New Person With {
.Id = 1,
.FirstName = "Jim",
.LastName = "Smith",
.Contact = New Contact() With {
.ContactId = 11,
.PersonId = 1,
.Phone = "666666666666",
.Address = "123 orange Lane",
.Email = "js@comcast.net",
.NickName = "SHANZ"}},
New Person With {
.Id = 2,
.FirstName = "Mary",
.LastName = "Bickmen",
.Contact = New Contact() With {
.ContactId = 20,
.PersonId = 2,
.Phone = "6666666666",
.Address = "33 Wyndmoor Lane",
.Email = "mb@gmail",
.NickName = "Hot apples"}}
}
ComboBox1.DataSource = people
ComboBox1.DisplayMember = "LastName"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim person = CType(ComboBox1.SelectedItem, Person)
Dim contact = person.Contact
Dim Get_Contact As New List(Of Contact)(contact)
Datagridview1.DataSource = Get_Contact
End Sub
End Class
Public Class Person
Public Property Id() As Integer
Public Property FirstName As String
Public Property LastName As String
Public Property Contact() As Contact
Public Overrides Function ToString() As String
Return FirstName
End Function
End Class
Public Class Contact
Public Property ContactId() As Integer
Public Property PersonId() As Integer
Public Property NickName As String
Public Property Email As String
Public Property Phone As String
Public Property Address As String
End Class
I tried somthing like this but it does not work.
Dim Get_Contact As New List(Of Contact)(contact)
Datagridview1.DataSource = Get_Contact
Thanks
Continue reading...