[2005]Databound DataGridViewComboBoxColumn

Clouddust

New member
Joined
Oct 4, 2006
Messages
2
Programming Experience
Beginner
Hi,

i'm trying to learning how to manipulate the DataGridView with database.
So, i added a 2 databasebound DataGridViewComboBoxColumn ("VehicleBrand", "VehicleModel")
so what i want to happen is to make the "VehicleModel" Column dependent on the selection of the "VehicleBrand" column. so, if i chose porsche then the model of porsche would be available in the "VehicleModel" column. and then everything inside the DataGridView will be saved and loaded from the database.
So, how am i suppose to do this?
 
You should have three tables: Vehicle, VehicleBrand and VehicleModel. VehicleModel would have a foreign key from the VehicleBrand table, while the Vehicle table would have a foreign key from each of the other two.

You would then add three BindingSources to your form.

The data source for the first BindingSource would be the Vehicle table. It would then be bound to the grid itself.

The data source for the second BindingSource would be the VehicleBrand table. It would then be bound to the Brand column of the grid.

The data source for the third BindingSource would be the VehicleModel table. It would then be bound to the Model column of the grid.

With all the data-binding set up at design time, all that's left for you to do in code is load the data into the DataSet and then save it when you're done. Everything else is taken care of for you.

This may sound complex but it is infact relatively easy. With experience the steps I've described would take about four minutes to complete. You probably don't have experience though, which is why you should start with simple projects to get acquainted with the principles. You should start with one table only. Make sure you know how to retrieve the data from the database and then save it again. Once that's done you would move onto using a BindingSource to populate a grid with your data. Once that's down add a single combobox column, then another until you've worked your way up to the scenario you are talking about. Walk before you run.
 
Back
Top