INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Get last (most recently added) record from a list

Get last (most recently added) record from a list

(OP)
Hi Folks

I have an app I wrote last year as an exercise in C#. In it I used a List object to accumulate a group of records that I eventually printed out on a form.

Now I am revisiting it and I would like to add an Undo feature. But to make this work I need to know what the information was in the last record added. It's important because I need to learn what was in the destination field before the action (a drag and drop operation). I'd like to query the list and get the ID # (stored in the record) or the index of the last records added so I can access to the fields to read them, then use the index (or ID # to delete the record from the list. But I'm having a heckuva time trying to figure out how to do this.

Is there anyone that can drop a little sample gode on how to do this? My searches of the online resources aren't giving me the answers I need.

Thanks

Craig (Amesville)

RE: Get last (most recently added) record from a list

Is this not working for you or something...?

[Code=c#]
List<string> myList = new List<string>();
for (int i = 0; i < 20; i++)
myList.Add(string.Format("Line {0}", i+1));
string lastLine = myList[myList.Count()-1];
[/code]

The result is that lastLine contains "Line 20"

If you look in the docs, their is an indexer listed in the properties of List. The C# docs are quite fantastic; if you search the Msdn you can typically find anything you need.

RE: Get last (most recently added) record from a list

And this is why I should stop replying using my android phone lol

RE: Get last (most recently added) record from a list

You won't only want to remove the laat list item (by index). For a general undo feature (which is not at all very basic) I'd add something similar to a transaction log (I'm a database guy).

So wherever you process drag&drop operations or whatever else changes the list, also add the operations done on the list in eg another list, kept in chronological order. You abviously need to store old values (if they changed) old items. In the simplest case you could copy the whole list, in it's current state, to have a snapshot you can use as undo step, but that'll be very memory intensive with large lists, obviously.

Bye, Olaf.

RE: Get last (most recently added) record from a list

(OP)
Thanks, I will try this out. For some reason I was having trouble hitting on the proper syntax to make this work and the examples I was looking at were not helpful.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close