간단한 응용 프로그램 - 주소록을 쓰고 있습니다. 사용자가 새 주소를 입력하면 기본 양식 (frmStart)에 표시되는 목록에 항목으로 추가됩니다. 하나의 양식을 사용하여 추가 및 편집합니다 (AddContForm). frmStart의 추가 단추가 제대로 작동하지만 편집 단추에 몇 가지 문제가 있습니다.이 단추를 누르고 새 항목을 입력하면 새로운 항목으로 추가되지만 이전 항목은 계속 남아 있습니다. 논리는 Contact.vb 클래스에 의해 처리됩니다. 이 문제를 해결하는 방법을 알려주십시오.다른 양식 간의 데이터 처리 VB.NET
:Contact.vb 여기
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
Public Sub Display()
Dim C As New 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)
End Sub
End Class
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 B As String
B = frmStart.Button
Dim C As New Contact
C.Display()
Me.Hide()
If B = "Edit" Then
C = DirectCast(frmStart.lstContact.SelectedItem, Contact)
frmStart.lstContact.SelectedItems.Remove(C)
End If
End Sub
Private Sub frmAddCont_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
업데이트 AddContFrm.vb
다음Public Class frmStart
Public Button As String
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Button = ""
Button = "Add"
frmAddCont.ShowDialog()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
Button = ""
Button = "Del"
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
Button = ""
Button = "Edit"
Dim C As Contact
If lstContact.SelectedItem IsNot Nothing Then
C = DirectCast(lstContact.SelectedItem, Contact)
frmAddCont.ShowDialog()
End If
End Sub
End Class
frmStart.vb
입니다 : 여기에 코드입니다AddForm의 데이터가 이전 데이터인지 새 데이터인지는별로 신경 쓰지 않습니다. 이 코드가 내 목표를 달성하는 데 어떻게 도움이 될지 이해할 수 없습니다. 나는 문제를 지금 생각하는 내가 목록에서 이전 항목을 편집 할 때 삭제되지 않습니다 (내가 내 질문에 표시 한 믿을) - 나는 그것을 삭제하려고 (if 조건을 사용하고 어떤 버튼이 눌려 졌는지 확인함으로써) 그러나 노력했다. 어떤 이유로 든 제대로 작동하지 않는 것 같습니다. 나는 당신의 코드가 나를 도울 수있는 방법을 이해하지 못한다. 가능하다면 더 잘 설명하라.