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

  • From: "Haden Pike" <haden.pike@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 16 Aug 2009 00:02:31 -0400

That would probably work Alex, except that the entries need to be in the list 
first, which is what I think the question is here.

Haden Pike
Email: haden.pike@xxxxxxxxx


From: Alex Hall 
Sent: Saturday, August 15, 2009 10:33 PM
To: programmingblind@xxxxxxxxxxxxx 
Subject: Re: C# question, binding arrays of objects to a list box, can it be 
done?


I am not much for fancy things like that, but the first thing that jumps to my 
mind is having a property called "id" or something; whenever you do anything 
with the class, you get the id first, then, if the user deletes an entry from 
the listbox, you can know which one they deleted by looking at the id of the 
class entry. Just a thought.


Have a great day,
Alex
New email address: mehgcap@xxxxxxxxx
  ----- Original Message ----- 
  From: Christy Schulte 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Saturday, August 15, 2009 10:15 PM
  Subject: C# question, binding arrays of objects to a list box, can it be done?


  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: