How Do I display formatted text from an object in a list box
Posted on 2004-10-22
This is a moderately difficult problem to put into words... However, I'll attempt to do my best.
For starters, I have a list box lbxPeople in which I am storing objects of classPeople.
I add the people to the list box with the following command, using my DataSource dsPerson and pulling records from table tblPersonRow
foreach (dsPerson.tblPersonRow p in dsPerson1.tblPerson.Rows)
personEntry = new classPerson(p.Person_ID, p.Last_Name);
I've looked in MSDN and the information on databinding sucks...
What I need to know is how to get my data out of the list box....
What I want to do is something like this...
tbxLastName.Text = lbxPlayers.Items[lbxPlayers.SelectedIndex].strLastName
but, the only option I get after SelectedIndex]. Is ToString(), GetHashCode(), Equals(),
So, I can see a couple ways of solving this problem. Either figure out how to data bind the combo box, or just continue with the above reasoning and getting the info out of the list box. Either solution would work for me.
Oh, I am using .net 2003 if that matters