Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collection Problem

Status
Not open for further replies.

ColinM

Programmer
Jun 29, 2000
189
TH
I have a collection which I wish to display in a datagrid.
It is a collection of a Name class which has Forename & Surname.
This works fine except I would also like to display the indexer of the collection, to give me a line number, in the datagrid like so:

1 John Smith
2 Bob Jones


Any ideas how I could go about this?
 
I don't think you can do this, as a collection (and you didn't specify what type you're using) doesn't really expose the value it uses internally to track item order (assuming it even has one). I think you'll have to either assign it yourself, or wrap the collection class you're using in your own wrapper class that does the assignment (keeps track of the most recently used value). In either case, you'll have to fiddle around with the values when you delete something from the middle of the collection.

Chip H.
 
Thanks for the reply.

I've gone along the lines of what you suggested, and added a LineNo field to the class. The LineNo field is set to equal count, which is a static int which gets incremented in the constructor. This seems to at least work, if slightly untidy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top