Solved

Create a Combo Box in a form that then updates a data grid view

Posted on 2014-11-18
4
170 Views
Last Modified: 2014-11-25
Ok very new to this.  I am using Visual Studio 2013.  I have 3 tables I am working with from a database the database is called GC_Emp_data, the tables are TrainingCourse, Positions, and then Training_Positions.  The training course has a list of all the courses the positions has all positions, and the last table merges the to together via the ID number.  So a training course could be in multiple positions.  What I wanting to do is Select a Training course via a combo box and then it populate a datagridview that will allow me to see what positions that it's has assigned in the (training_posoition table) and also allow me to add new positions to that table.  Not sure where to start and cannot find the right starting point.
0
Comment
Question by:sharris_glascol
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 40450060
You'll need to query your TrainingCourse table to populate your combo box and return a dataset or datatable with the courses.  Then you'll need to provide information for the following to load up the combo box.

            comboBox1.DataSource = //DataSet name or datatablename
            comboBox1.ValueMember = //database column name, probably the course ID
            comboBox1.DisplayMember = //database column name, probably the name of the course

Open in new window


Once you have the combobox populated you'll want to create an event for the selected index changed (double click the combo on your form) so that when a course selection is made you can have your program query the Training_Positions table based on the valuemember of your course selection.  Then return a dataset or datatable with the results and set the datasource of the datagridview to the name of the dataset or datatable

dataGridView1.DataSource = //dataset or datatable name

Open in new window


As far as adding new positions, how were you envisioning you would accomplish that task?  Do you have the pieces in place to be able to connect and query your database from your program or do you need help from the ground up?
0
 

Author Comment

by:sharris_glascol
ID: 40450084
All I want to do is in the datagridview is add positions via a combo box that references the positions table and updates the training/positions table.
0
 
LVL 9

Expert Comment

by:dustock
ID: 40450116
Then you'll need to load a combobox with the list of positions and when you select one and click a button, or just select one you can run an insert statement and then query your database again to get the updated view in your datagridview.  

I can help you accomplish any of this, but I need more information on what you need help with.  The more vague you are in your request the more difficult it is for myself and other experts to assist you.  Do you need help with the code, the queries, the logic?  Do you have any code in place that you've tried but need help to debug?
0
 
LVL 32

Expert Comment

by:it_saige
ID: 40458460
Using what I have understood to be your requirements.  I threw together this quick example in VS2013.  Let me know if this is what you were after.

-saige-
EE-Q28564627.zip
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now