How to Configure ComboBox in DataGridView

I feel it would be necessary to create a tutorial on how I program the ComboBox in DataGridView. So, this tutorial will guide you on how to:

  1. Add DataSet
  2. Create a master/detail form
  3. Add ComboBox in DataGridView

How to add a DataSet

1. Click on the Data Sources.

2. Click Add New Data Source.

Follow the data source configuration wizard. Be careful though on naming your DataSet. In my case if I add two tables like Orders and Order Details I named my DataSet as OrdersDataSet.

3. Edit the newly created DataSet and add a relationship as shown below:

[inline:Add_Relationship.jpg=Add Relationship]

[inline:Orders_and_Order_Details_Relationship.jpg=Orders and Order Details Relationship]

Click on the OrderID field in the Orders table and change the AutoIncrement Property to True. Set the AutoIncrementSeed and AutoIncrementStep value to 1.

[inline:3=AutoIncrement OrderID

How to add a Master/Detail form

One of the most awaited features I like in MS Access is the ability to add a master/detail form easily using a wizard. In Visual Basic .NET this can be done easily also by using the drag and drop operation. After you add a DataSet with Orders and Order Details table follow the following steps to add a master/detail form.

1. Drag the Orders Table from the Data Sources window to Windows Form.

In the Data Sources window change how you would like to view your form in Windows Form. In this case the Orders table should be displayed in Details view. Don’t be confused about the term master/detail form. This simply means that we will display the Orders Table using TextBoxes and not in DataGridView control.

[inline:Orders_Details_View.jpg=Orders Details View]

2. Drag the Order Details Table under the Orders Table.

[inline:Order_Details.jpg=Order Details]

How to add ComboBox in DataGridView

1. Right click DataGridView control and click Edit Columns.
2. Delete other fields and leave only Qty, ProductID, and SalesPrice.
3. Click ProductID in the selected columns section and change the column type to DataGridViewComboBoxColumn.

[inline:Product_ColumnType.jpg=Product ColumnType]

4. Edit the Data properties of ProductID

[inline:Product_Column_Data_Properties.jpg=Product Column Data Properties]

I hope this help.

Comments

Submitted byAnonymous (not verified)on Fri, 12/18/2009 - 22:32

hi while adding relationship in this i get a error that says parent key and child key are identical
Submitted byAnonymous (not verified)on Wed, 02/17/2010 - 20:40

how to add datas from a table to combox ? thanks
Submitted bymanish tiwari (not verified)on Thu, 04/11/2024 - 12:56

please

Add new comment