Solved

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

Posted on 2014-11-18
4
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 34

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

734 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