VB.NET editing existing that with a form

Posted by user127147 on Stack Overflow See other posts from Stack Overflow or by user127147
Published on 2010-04-28T16:19:07Z Indexed on 2010/04/28 16:23 UTC
Read the original article Hit count: 222

Filed under:
|
|

Hi there,

I have a simple questions that puzzles me. I need a little bit of refreashment with VB as I have been away for a while. I have a form that adds new contacts. New contacts are added by pressing an appropriate button and they appear as an entry in the list on the form. I try now to add an edit button that will edit existing entries. User will select a given entry on the list and press edit button and will be presented with an appropriate form (AddContFrm). Right now it simply adds another entry with the same title. Logic is handled in a class called Contact.vb Here is my code.

Public Class Contact
    Public Contact As String
    Public Title As String
    Public Fname As String
    Public Surname As String
    Public Address As String
    Private myCont As String
    Public Property Cont()
        Get
            Return myCont
        End Get
        Set(ByVal value)
            myCont = Value
        End Set
    End Property
    Public Overrides Function ToString() As String
        Return Me.Cont
    End Function
    Sub NewContact()
        FName = frmAddCont.txtFName.ToString
        frmStart.lstContact.Items.Add(FName)
        frmAddCont.Hide()
    End Sub
    Public Sub Display()
        Dim C As New Contact
        'C.Cont = InputBox("Enter a title for this contact.")
        C.Cont = frmAddCont.txtTitle.Text
        C.Fname = frmAddCont.txtFName.Text
        C.Surname = frmAddCont.txtSName.Text
        C.Address = frmAddCont.txtAddress.Text
        'frmStart.lstContact.Items.Add(C.Cont.ToString)
        frmStart.lstContact.Items.Add(C)
    End Sub
End Class

AddContFrm

Public Class frmAddCont
    Public Class ControlObject
        Dim Title As String
        Dim FName As String
        Dim SName As String
        Dim Address As String
        Dim TelephoneNumber As Integer
        Dim emailAddress As String
        Dim Website As String
        Dim Photograph As String

    End Class

    Private Sub btnConfirmAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirmAdd.Click

        Dim C As New Contact
        C.Display()
        Me.Hide()

    End Sub

    Private Sub frmAddCont_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

and frmStart.vb

Public Class frmStart

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        frmAddCont.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click

        Dim DelCont As Contact
        DelCont = Me.lstContact.SelectedItem()
        lstContact.Items.Remove(DelCont)

    End Sub

    Private Sub lstContact_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstContact.SelectedIndexChanged

    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Dim C As Contact
        If lstContact.SelectedItem IsNot Nothing Then
            C = DirectCast(lstContact.SelectedItem, Contact)
            C.Display()
        End If
    End Sub
End Class

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about data