473,383 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 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 1270

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: GTi | last post by:
In Win32 I have a function that opens several Dialogs and put the window handle in a listbox (together with a string): HWND hWnd = CreateDialogParam(...) LB_SETITEMDATA, index, (LPARAM)hWnd); ...
1
by: MrNobody | last post by:
Hi, I'm doing something where I add custom objects to a ListBox which have aToString() method overriden so it displays what I want. When adding instances of these custom objects to the ListBox I...
1
by: Spock | last post by:
Hi. I have a form with a listbox and a few label fields all bound to a dataset. When i navigate the listbox the labels change accordingly. so far everything works good. I made a button to...
8
by: Dan | last post by:
Is there any way to assign a tag value to each item in a listbox?
9
by: DFS | last post by:
You might also find other uses ========================================================= Public Function getSelections(selType As String, selSeparator As Boolean, selList As ListBox, selCol As...
1
by: WhiteWizard | last post by:
First my apologies, this may be longer than the normal question. I have a windows app (.NET 2.0, VS2005), and I've written a user control that will allow the user to "drag and drop" a directory...
18
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
4
by: Anand Ganesh | last post by:
Hello All, I want to go through each item in a Listbox collection. How will I do this? I was looking for ListBoxItem but nothing is available? Any suggestions please? Thanks Anand Ganesh
5
by: lukasmazur | last post by:
Hi I have a problem with using listBox1. I have a two forms form1 and form2. In form1 are controls listBox1, textBox1 and button witch creating object of class Form2. In class Form2 I create a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.