On 18 Feb 2006 13:43:51 -0800, "Brett Romero" <ac*****@cygen.com>
wrote:
Right. Now, as for the ToString() method, which of the two fields will
it choose to send back if both are string fields? There must be some
logic going on there to decide field1 or field2. Does it matter if
the two fields in my object are int and string fields. Both of them
are also displayable. Which will ToString() send back now?
Brett
You will have to write code to get back what you want.
Sometimes a picture is worth a thousand words.
Try something like this, Brett:
private void MainForm_Load(object sender, EventArgs e)
{
// People is inherited from List<T>
PeopleList people = new PeopleList();
// add some person objects to the list
people.Add(new Person(1, "Fonda", "Hanoi", "Jane"));
people.Add(new Person(2, "Kerry", "John", "F"));
// bind the list to the list box
LearningListBox.DataSource = people;
}
private void LearningListBox_SelectedIndexChanged(object sender,
EventArgs e)
{
// get the person object from the selected item
Person person = (Person)LearningListBox.SelectedItem;
// get the data from the person object and use it the way you want
int id = person.ID;
string lastName = person.LastName;
string firstName = person.FirstName;
string middleName = person.MiddleName;
}
// here is the Person.ToString() method
public override string ToString()
{
return string.Format("{0}, {1} {2}", _current.lastName,
_current.firstName, _current.middleName);
}
Otis Mukinfus
http://www.otismukinfus.com http://www.tomchilders.com