We help IT Professionals succeed at work.

Use listbox with SQL table data to fill remaining form controls upon selection

I have an SQL table, (tblFPDetail), that I would like to retrive data from and display this information in several textboxes on my form. My table has a foreign key (PCIDNum) with another table,(PCinfo). The PCInfo table contains a field, PCName. I would like to be able on my form to have a listbox that shows the PCName values of which the user would select the appropriate one. The remaining textboxes on the form would then fill with the related data from tblFPDetail. The user should then be able modify the values within the textboxes with data from tblFPDetail and select save from the toolstrip and have the values within tblFPDetail be modified.
Thanks in advance for any help!
Comment
Watch Question

Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
IronDriver,

You understand that what you are asking needs a lot of code to do. I will show you the basics and you can start working with that but it's difficult to explain everything in a post. I will show you how to retrive data from the form and populate the listbox (in the example I use a listview) but you can use that. Check this example that I post it yesterday http://www.experts-exchange.com/Microsoft/Development/.NET/Visual_Studio_.NET_2005/Q_23111538.html

Then what you have to do is when the user change the selection on the listview (listview selectedindexchange event) you read again from the db and populate the textboxes.

You can also use a datagridview control and bind using the available wizards. With this you can update/delete and insert direcly in the datagridview.

Author

Commented:
Thank you jp for the response...sorry so long to follow up. It has taken me a little while to actually get this to work as you have referenced in some of your prior comments. I have gotten the listview to work fine but that is about half the battle. I have included a diagram in PDF format the better illustrates what I am looking for. I may be headed about this in the wrong manner and if so feel free to let me know a simpler way...or if I am just wayyyyy off.   Thanks!
Simple-Table-Diagram.pdf
IT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
HI,

I have seen you Diagram but if you already filled the list the you can do the next step. When you populate a listview you should include a column with the ID. When you select the ID on the listview you do a select statement to the database and populate the fields. This is almoust the same as populate the listview but since it will retrieve only one field you will set the fields to the form textboxes.

After this you only need to build a update statement and save the data to the database.

I don't know wath you have so far and your dificulties so it's better if you expose them and show what you have so far.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.