add button problem

hello,
I have an add button that is working fine the problem
is that when I add a new record to the .ini file from
edit.vb and I click save I go to main.vb but the new
record doesnt appear in the listbox. im using
this code http:Q_21832094.html and this is my
add buttom

Public Class frmAdd

    Private Sub cmdCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancel.Click
        frmMain.Enabled = True
        frmMain.Activate()
        Me.Close()
    End Sub

    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Dim FileNo As Short
        On Error Resume Next

        FileNo = FreeFile()
        FileOpen(FileNo, "C:\Accounts.ini", OpenMode.Append, , OpenShare.Shared)
        PrintLine(FileNo, txtID.Text & ";" & txtName.Text)
        FileClose(FileNo)

        frmMain.Enabled = True
        frmMain.Activate()
        Me.Close()
    End Sub
End Class
apleloisAsked:
Who is Participating?
 
Fernando SotoRetiredCommented:
If you are using Visual Studio 2005 then try this.

In your main form change this line of code:

    Private arrPersons As New ArrayList

to :

    Public arrPersons As New ArrayList

Then in your edit.vb form add the following code to the cmdSave_Click event:

        ' Old code
        FileNo = FreeFile()
        FileOpen(FileNo, "C:\Accounts.ini", OpenMode.Append, , OpenShare.Shared)
        PrintLine(FileNo, txtID.Text & ";" & txtName.Text)
        FileClose(FileNo)

        ' Added code
        Dim p As New frmMain.Persons
        p.first = txtName.Text 'First name
        p.last = txtLast.Text
        p.email = txtEmail.Text
        p.phone = txtPhone.Text
        frmMain.arrPersons.Add(p)
        frmMain.lstAccounts.BeginUpdate()
        frmMain.lstAccounts.DataSource = Nothing
        frmMain.lstAccounts.Items.Clear()
        frmMain.lstAccounts.DisplayMember = "first"
        frmMain.lstAccounts.DataSource = frmMain.arrPersons
        frmMain.lstAccounts.EndUpdate()

Fernando
0
 
Carl TawnSystems and Integration DeveloperCommented:
It won't appear automatically. You need to repopulate the listbox yourself.
0
 
Fernando SotoRetiredCommented:
Are you using Visual Studio 2005 VB.Net?
0
 
apleloisAuthor Commented:
Gracias!!!
0
 
apleloisAuthor Commented:
maybe you can help me with http:Q_21833498.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.