0

Hi I require assistance on how to show browsing First, Next Previous and Last in C#. I need to split a text file with numerous records to show this information and I am struggling. If i could get a helping hand it would b much appreciated.

Thanks

Ryan

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by darkagn
0

Read the text file records into an array or some other list data structure. Let's call it myList for this example.
Create a reference to the current record. Let's call it currentRecord for this example.
Create a reference (int) to the current record's index in the list. Let's call it currentIndex for this example.

Here is how I would write the First and Previous methods. Next is opposite of Previous and Last is opposite of First so I will leave them to you.

public void First()
{
  // make sure we can get the data
  if (myList.Count > 0)
  {
    // first index in the list is 0
    currentIndex = 0;
    currentRecord = myList[currentIndex];
  }
  else
  {
    currentIndex = -1; // -1 to indicate nothing selected
    currentRecord = null;
  }
}

public void Previous()
{
  // ensure we can get a previous record
  if (myList.Count > 0 && currentIndex > 0)
  {
     // decrement the current index and update the current record
     currentIndex--;
     currentRecord = myList[currentIndex];
  }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.