Loading

Display Record in DataGridView Based on ComboBox Selected Value

Submitted by: 


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.



Download Code:: 

Comments

Sir Jay

How to convert .net to vb6?

admin's picture

I don't have much time converting this to vb 6 for now.

It is good to have this tutorial. But can you help me, how to display none in the combobox when it is loading, so that if the data is bigger the application can start quickly?

admin's picture

One of the approach if you have a lot of record to bind in a ComboBox is to filter the record based on the character that you have type in a combobox. This can be done in the Change event of a combobox.

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?

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.

admin's picture

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.

sir can you plz help me in combox view how to show value in datagrid view my email id is (link_atif@yahoo.com)

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?

pls help us make a comuterized cashier system

how to add the data grid values to a ms access table in vb.net

kimy's picture

Hi admin am beginner, and gusto ko sana pano gumawa ng design
for online reservation.
salamat po ng marami.
God bless you.

kimy

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

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 naser_wahby@yahoo.com.

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.

i can do that pls provide the vb code

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!

Bro,

Could you plz tell what have you done to make your code work........if at all it was resolved..

admin's picture

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.

this is the good article
check this link

http://www.mindstick.com/Articles/846b3763-8c38-47d4-b899-5db9cc6fea95/

Good Job

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.

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

Pages

Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.