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

  • From: "black ares" <matematicianu2003@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 16 Aug 2009 11:05:24 +0300

the datasource property
can be assigned a array of objects, and when you delete something, it deletes 
the entire object from the array list.
so no decoupling of the first name and last name.
also for make sorting you must implement icomparable interface and to write the 
compareto method.
this way the array will know how to sort the data.

  ----- Original Message ----- 
  From: Christy Schulte 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Sunday, August 16, 2009 5:15 AM
  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: