English 中文(简体)
VB. NET 编辑现有表格
原标题:VB.NET editing existing that with a form
  • 时间:2010-04-28 16:19:07
  •  标签:
  • vb.net
  • edit

我有一个简单的问题,令我困惑。 由于我已经离去,我需要稍微与VB的复仇。 我的表格增加了新的接触。 新的接触通过一个适当的纽芬兰语加以补充,并作为表格清单的条目出现。 我现在试图增加一个ed子,把现有的条目ed开。 用户将选择名单上的某一条目和报章,并提交适当的表格(AddContFrm)。 现在,它只是增加了另一个标题相同的条目。 逻辑处理方式是“接触”一类。 这里是我的法典。

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

iii

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
问题回答

You haven t really added a question but looking at your code it s a bit weird.
If you click Add it will show frmAddCont and then in the confirm button of that form it ll save the data, but if you click Edit it won t show the form and will only add the same data again. I think you re missing a frmAddCont.Show() in your edit button handler.

However, all in all, you re mixing data with GUI too much. The Contact class should know nothing about frmAddCont, rather, the Add and Edit buttons in the main form should show frmAddCont as required (but I would do ShowDialog rather than Show to make it Modal) and if it s in edit mode I d send in the Contact to be edited to frmAddCont and then when the user press confirm I d amend/create the Contact as needed and if it s an Add I d have a method that the main form could call to get out the new Contact.
I think it s fine for the GUI to know about your Contact class, but the Contact class should now know anything about the forms.





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签