Display Record in DataGridView Based on ComboBox Selected Value

In this tutorial I will teach you on how to display related record based on the selection value from a ComboBox.

The example displays a student’s subject in a DataGridView after a SelectedIndexChanged event of a ComboBox.

This tutorial assumes that you already know how to add a DataSet in your project.

The following are important steps in order to understand how I made this simple program.

1. Bind a ComboBox

[inline:ComboBox_Data_Binding.jpg=Bind a ComboBox]

2. Add a query in the Course Table under DataSet designer

[inline:DataSet.jpg=Add a query in the Course Table under DataSet designer]

3. Edit DataGridView columns after binding from Data Source

[inline:Edit_Columns.jpg=Edit DataGridView columns after binding from Data Source]

4. Select only the following field by removing unnecessary columns

[inline:Columns.jpg= remove unnecessary columns]

5. In the SelectedIndexChanged event of the ComboBox use the FillBy method instead of Fill method

[inline:FillBy.jpg=FillBy method]

As you can see in the DataSet designer there are two fill method in a Course table name Fill and FillBy. FillBy has a parameter named StudentID. This will tell our TableAdapter to filter the record using the FillBy method.

Comments

Oh thanks for the suggestion. Can you give example? Just say I have four categories/items building, car, animal and electronic. I have not tried yet, but in my point of view, if the future we want to add some more categories/item, to the database, I think we would find difficulty. Don't you think so?
Submitted bydhammasirion Fri, 12/18/2009 - 00:32

I often find the member of this forum asking the programmer to convert their program to VB6 from the higher version. I think it is better if those who ask upgrade their software to higher version. You can get the Visual Studio 2008 by downloading from torrent or just buy it in the shop. I'm sure the price is not expensive because mostly they are pirated.

Yes that's true. But some people is asking to downgrade the source code is due to the fact that their professor is still using VB 6.0 in their class. One reason is their computer may be cannot meet the specs of VB.NET. For now I prefer to work with VB.NET as it has a lot of changes that makes coding easier and faster.

I think if is so, then they may give a try to REALbasic. I just this this software. It's good and almost similar to VB, yet more powerful. This software is cross-platform. The coding is simple and you can convert the VB code to this software too. Just try it.
Submitted byAnonymous (not verified)on Thu, 01/14/2010 - 19:01

Hello SIr, I want to develop a school management system using vb at front end and oracle as back end.Can u tell me some initial steps so that i could handle oracle without any problem? Note:I dont know very much about using oracle.Can I develop it by only using sql server 2000/2005?
Submitted byAnonymous (not verified)on Wed, 01/27/2010 - 11:05

pls help us make a comuterized cashier system
Submitted byAnonymous (not verified)on Mon, 02/15/2010 - 14:46

how to add the data grid values to a ms access table in vb.net
Submitted bykimyon Wed, 03/03/2010 - 22:53

Hi admin am beginner, and gusto ko sana pano gumawa ng design for online reservation. salamat po ng marami. God bless you.
Submitted byAnonymous (not verified)on Wed, 04/21/2010 - 05:02

I downloaded it but when i run the program i get an error: A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll Do you know what to do? And is it possible to edit the records and that the datasource is then updated? many thanks
Submitted byAnonymous (not verified)on Sun, 05/16/2010 - 18:20

Hallo Crew, I wonder if you have more tutorials to show us how you can make invoice from different tabel , like customer or produkt, and finally the calculate isseu. Please send a mail to me my mail is [email protected]. Please i hope the you write me back with more information. Also if you have a book or somthing to print uit and to follow it wil be great. Of course against payment. Thank You.
Submitted byAnonymous (not verified)on Fri, 09/03/2010 - 18:03

i can do that pls provide the vb code
Submitted byAnonymous (not verified)on Tue, 11/02/2010 - 09:14

I am also trying to display a record based on combobox selection. I have the query started but can not get a WHERE statement to work. In Step 2 The WHERE statement says (StudentID = ?) how do I get this to work. I get a incorrect syntax error. Right now my datagridview shows every record entered and my combobox shows the correct Names I have in the view. Thanks anybody!

Are you using MS Access database? Because if you are using SQL Server then you have to change the parameter to something like: (StudentID = @StudentID

Yes, I am using SQL Server and coding in C#. I have difficulty in building the query correct. It says " Unable to Parse the Query Text" here is the query: SELECT Primary_ID, Date, [Full Name], [Vehicle Make], [Vehicle Model], Gas_Filled, Mileage FROM Gasolinetable WHERE ([Full Name] = @Full Name) you might have noticed there is space between Full and Name... Any help would be greatly appreciated... Thank you.
Submitted byAnonymous (not verified)on Tue, 03/01/2011 - 16:51

Good Job
Submitted byAnonymous (not verified)on Wed, 10/26/2011 - 19:52

In reply to by Anonymous (not verified)

what i do now if combobox text will not change on display after selected in visual studio 2008. i linked combobox with database. Then combobox selected text will not change during debug. could u help me this problem.
Submitted byAnonymous (not verified)on Fri, 10/28/2011 - 08:48

Hi Sir, this is chester of Manila, can you please give me sample Sales force System of Real State Company, i want to have a basis before i will do these system

Add new comment