Windows Forms: Add Combobox to DataGridView in C#

By FoxLearn 6/8/2017 8:13:01 PM   8.79K
Add Combobox to DataGridView, bind data to Combobox and DataGridView in C# using Entity Framework Database First

Step 1Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "ComboboxDataGridView" and then click OK

add combobox to datagridviewStep 2: Design your form as below

add combobox to datagridview in c#

Step 3: Create an Entity Framework Model First, then add Category and Product table to your EF Model

c# entity framework

Step 4: Add code to handle your form as below

​using System;
using System.Linq;
using System.Windows.Forms;

namespace ComboboxDataGridView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //Get category, product data from the Northwind database
            using (NorthwindEntities db = new NorthwindEntities())
            {
                productBindingSource.DataSource = db.Products.ToList();
                categoryBindingSource.DataSource = db.Categories.ToList();
            }
        }
    }
}

VIDEO TUTORIALS