Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've asked a previous question associated with this before(http://www.codeproject.com/Questions/606417/), that problem was solved. Now, I have a question about displaying the data. The program is currently displaying website names in a list box, but how do I display the website's other data in text boxes and such? In the Access 2013 database, there's information about each website (website link, whether website has mobile site/not, etc.). When someone selects a specific item from the list box (by pressing a button that says "View Website Info"), how could I set it up to display the website's other data without having to type in, individually, each website's data in the coding (thus defeats the purpose for the database)? Sorry if I've made this question confusing!
Posted
Comments
[no name] 17-Jun-13 15:20pm    
Connect to your database, query the data you want, iterate through your data reader, put the data wherever you want the data to go. Plenty of examples laying around everywhere.

1 solution

List boxes have the extraordinarily useful ability to accept ANY object as a list item; the text displayed in the box is taken from the object's ToString method.

For stuff like this, I would create a basic "envelope" class, with two properties: one holding the name of the website, and the other holding the database index that uniquely identifies the associated record. The constructor of the class would take both properties as parameters. The ToString method is overridden to return the name property. Each entry in the database gets its own envelope class, and each envelope is added to the list box' list of items.

If you want the data displayed real time, intercept the list box' SelectedIndexChanged event, which will tell you when the user makes a selection. Or, you can have the user click a button to see the data. In any case, convert the box' SelectedItem to your class, retrieve the database index associated with the selected website name, then make a quick call to the database using that index to retrieve the data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900