so far here are my codes... thanks for the help
however, there are still glitches in the process
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;
// add private fields
private string[] lines;
private int nextLine = 0;
private void frmCustomerDetails_Load(object sender, EventArgs e)
{
//Reads records from a file
lines = File.ReadAllLines(@"C:\mp2.txt");
DisplayRecord(0);
}
private void DisplayRecord(int index)
{
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];
if (index < lines.Count - 1) nextLine = index + 1;
// lines.Count didn't worked (System.Array doesn't not contain a definition
// for 'Count'
}
private void btnFirst_Click( object sender, EventArgs e)
{
DisplayRecord(0);
}
private void btnNext_Click( object sender, EventArgs e)
{
DisplayRecord(nextLine);
}
I also added two more features, but I don't where to start:
// btnPrev - Displays records before the 2nd, 3rd, 4th......
private void btnPrev_Click( object sender, EventArgs e)
{
// What to write?
}
// btnLast - Displays the last record in the .txt file
private void btnLast_Click( object sender, EventArgs e)
{
// What to write?
}
Scott LyslePosted Dec 13, 2007, 10:25 AM
You could try something like this:
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; namespace JunkAnswer { public partial class Form1 : Form { SortedList sl; int pos; public Form1() { InitializeComponent(); pos = 0; } private void Form1_Load(object sender, EventArgs e) { sl = new SortedList(); StreamReader sr = File.OpenText("c:\\temp\\junk.txt"); string strTemp = string.Empty; ; int i = 0; while ((strTemp = sr.ReadLine()) != null) { sl.Add(i, strTemp); i++; } sr.Dispose(); DisplayValue(0); } private void btnNext_Click(object sender, EventArgs e) { if (pos < sl.Count - 1) { pos++; DisplayValue(pos); } else { return; } } private void btnBack_Click(object sender, EventArgs e) { if (pos > 0) { pos -= 1; DisplayValue(pos); } else { return; } } private void btnFirst_Click(object sender, EventArgs e) { DisplayValue(0); pos = 0; } private void btnLast_Click(object sender, EventArgs e) { DisplayValue(sl.Count - 1); pos = sl.Count - 1; } private void DisplayValue(int val) { foreach (DictionaryEntry de in sl) { if (de.Key.ToString() == val.ToString()) { string[] tmp = de.Value.ToString().Split('#'); txtNumber.Text = tmp[0]; txtName.Text = tmp[1]; txtState.Text = tmp[2]; return; } } } } }