471,321 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

ListBox and class instances

Hello,
I'm making a small app that loads users from an xml file. After loading
the data, new instances of a custom users class are initalized and at
the same time a listbox items are initialized with the users. My
question is when the listbox is changed how could I update a property
or know that Item in the list box, which instatnce it references.

//code to load users into usersDS
........
users[] theUsers = new users[anything.Count];
int counter = 0;
foreach(datarow user in userDS){

theUsers[counter] = new user(proper1, prop2);
listbox1.items.add(theUsers[counter].toString());
counter++;
}
listbox1_OEvent(){
//which users instance I'm I?
}
How do I Know which user instancce does the selected item represents?

Jan 24 '06 #1
1 1227

Mr. Bean wrote:
Hello,
I'm making a small app that loads users from an xml file. After loading
the data, new instances of a custom users class are initalized and at
the same time a listbox items are initialized with the users. My
question is when the listbox is changed how could I update a property
or know that Item in the list box, which instatnce it references.

//code to load users into usersDS
.......
users[] theUsers = new users[anything.Count];
int counter = 0;
foreach(datarow user in userDS){

theUsers[counter] = new user(proper1, prop2);
listbox1.items.add(theUsers[counter].toString());
There is a better way than this - just add the users objects
*themselves* to the listbox. A listbox automatically *displays* the
..toString() of its contents.
counter++;
}
listbox1_OEvent(){
//which users instance I'm I?
(users)listbox1.SelectedItem
}
How do I Know which user instancce does the selected item represents?


By adding the actual users objects this is made simple - the selected
item *is* a users object.

--
Larry Lard
Replies to group please

Jan 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by GTi | last post: by
1 post views Thread by MrNobody | last post: by
1 post views Thread by Spock | last post: by
1 post views Thread by WhiteWizard | last post: by
4 posts views Thread by Anand Ganesh | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.