adding records to .txt file... edit existing file... save edited file... Windows App

Dec 18 2007 6:45 AM

Here's my program that displays my .txt file: (Thanks Alan for the big help.)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;


private string[] lines;
private int currentLine = -1;


        private void frmCustomerDetails_Load(object sender, EventArgs e)
        {
            lines = File.ReadAllLines(@"C:\mp2.txt");
            DisplayRecord(0);

        }

        private void DisplayRecord(int index)
        {
            if (index < 0 || index >= lines.Length || index == currentLine)
               return;
            string[] records = lines[index].Split('#');
            txtCustomerID.Text = records[0];
            txtContactPerson.Text = records[1];
            txtAddress.Text = records[2];
            txtContactPerson.Text = records[3];
            txtContactNo.Text = records[4];
            currentLine = index;  
        }

Here's my problem....

Is there a way I could add records from the existing notepad (mp2.txt), wherein, you could still display all the previous items plus the one you've added? Another, is there a possibilty that I could still edit my previous record from the 'mp2.txt' and save it afterwards?

here's the thing

btn_Add - Adds a new record...then put on the last record of mp2

btn_Edit - edits the the one who is currently displayed by the textboxes...

btn_Save - saves the changes when Edit process was finished already....

btn_Cancel - if you wish to cancel the edit process..

 

(by the way, once added a new record, there should have an input recorded to the mp2.txt as well)

 

 

Sorry if I ask too much. I'm kinda confused with all these stuff. Noob me.

 

Thanks and God bless.


  


Answers (1)