I have a WPF form that shows a contact (Name, Address and State).
The GUI is bound to a CurrentContact
object and they are stored in a List<Contact>
.
I would like to add buttons to the bottom:
+-----+ +-----+ +-----+ +-----+ | << | | < | | > | | >> | +-----+ +-----+ +-----+ +-----+
Meaning first, previous, next and last.
Is there an easy control or convention to iterate through the list? Or do I need to store an currentItemIndex and roll my own?
Lists provide random access, so you don't need to iterate through them to get from one spot to another. In fact, it's probably inefficient to iterate if the list is very long; imagine you wanted to get to the last record from the first one, for example.
In any case, your four buttons would just be:
list[0]
list[currentIndex - 1]
list[currentIndex + 1]
list[list.Count - 1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With