C# question, binding arrays of objects to a list box, can it be done?

  • From: "Christy Schulte" <christy@xxxxxxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sat, 15 Aug 2009 21:15:31 -0500

Ok, let me see if I can explain the problem. I have a feeling I'm missing 
something obvious here, but I had a similar hang up in one of my VB assignments 
so, who knows.

This assignment is to create an address book application. The user is supposed 
to have the option to show a list box with all entries listed, but only show 
the last name and first name. The full entries include first name, last name, 
address among other things. The list box also must be sorted alphabetically. 
We're reading the initial entries from a file, but allowing for edits, 
additions, deletions, etc.

The way I'm doing this is that I created a class called entry, which has 
properties for first name, last name, address and so on. Then I have an array 
of entry objects, so that for example to get the first name of the third entry, 
I could use entries[2].FirstName.

So far so good, but I'm at a loss for how to get the information I want into 
the list box in such a way that the first and last names displayed there will 
stay connected with the rest of their object if deletions and edits are made. I 
keep thinking that datasource should play a part here, but when I research it 
it's either not what I want, or the explanation is way over my head. So am I 
going about this all wrong, or am I just missing something simple? One thing I 
considered is keeping name as a single property rather than trying to pull two 
different properties into the list together, but that still doesn't solve the 
problem of how to keep everything together when changes are made through the 
list.

I hope this makes some kind of sense, I know what I want to do but not how to 
explain it well or how to get it working. Any ideas would be greatly 
appreciated.

Other related posts: