?
Solved

add button problem

Posted on 2006-05-01
5
Medium Priority
?
218 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:aplelois
  • 2
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16579975
It won't appear automatically. You need to repopulate the listbox yourself.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 16580175
Are you using Visual Studio 2005 VB.Net?
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 16580873
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
 

Author Comment

by:aplelois
ID: 16581009
Gracias!!!
0
 

Author Comment

by:aplelois
ID: 16581014
maybe you can help me with http:Q_21833498.html
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question