title: How do I make three cascading comboBoxes in a DataGridView?
body: <p>I am a beginner programmer developing a C# WinForms / SQL solution in VS 2015 Professional.</p>
  
  <p>Can anybody please help me with the code below?  I am trying to implement cascading comboBoxes inside a <code>DataGridView</code> to do the following:</p>
  
  <p>ComboBox1 lists courses the school has;
  ComboBox 2 lists the modules for the selected course;
  ComboBox 3 lists the classes for the selected module.</p>
  
  <p>I've googled extensively but nothing I've tried has worked so far... This is so frustrating!</p>
  
  <p>Thank you. I really appreciate your time and help. Here's the code I'm trying:</p>
  
  <pre><code>public partial class Alunos : Form
      {
          public Alunos()
          {
              InitializeComponent();
          }
  
          BindingSource filteredModulosBS = new BindingSource();
          BindingSource filteredTurmasBS = new BindingSource();
  
  
          private void Alunos_Load(object sender, EventArgs e)
          {
              this.alunosTableAdapter.Fill(this.bremingtonBackEndDataSet.alunos);
              this.alunos_detTableAdapter.Fill(this.bremingtonBackEndDataSet.alunos_det);
              this.cursosTableAdapter.Fill(this.bremingtonBackEndDataSet.cursos);
              this.modulosTableAdapter.Fill(this.bremingtonBackEndDataSet.modulos);
              this.turmasTableAdapter.Fill(this.bremingtonBackEndDataSet.turmas);
  
              DataView dvM = new DataView(bremingtonBackEndDataSet.Tables["modulos"]);
              filteredModulosBS.DataSource = dvM;
  
              DataView dvT = new DataView(bremingtonBackEndDataSet.Tables["turmas"]);
              filteredTurmasBS.DataSource = dvT;
          }
  
          private void alunos_detDataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
          {
              if (e.ColumnIndex == ComboBoxColumnModulo.Index)
              {
                  DataGridViewComboBoxCell dgcbm = (DataGridViewComboBoxCell)alunos_detDataGridView[e.ColumnIndex, e.RowIndex];
                  dgcbm.DataSource = filteredModulosBS;
                  this.filteredModulosBS.Filter = "cod_curso='" + this.alunos_detDataGridView[e.ColumnIndex - 1, e.RowIndex].Value.ToString() + "'";
              }
  
               if (e.ColumnIndex == ComboBoxColumnTurma.Index)
               {
                  DataGridViewComboBoxCell dgcbt = (DataGridViewComboBoxCell)alunos_detDataGridView[e.ColumnIndex, e.RowIndex];
                  dgcbt.DataSource = filteredTurmasBS;
                  this.filteredTurmasBS.Filter = "cod_modulo='" + this.alunos_detDataGridView[e.ColumnIndex - 1, e.RowIndex].Value.ToString() + "'";
              }
          }
  
          private void alunos_detDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
          {
              if (e.ColumnIndex == this.ComboBoxColumnModulo.Index)
              {
                  DataGridViewComboBoxCell dgcbm = (DataGridViewComboBoxCell)alunos_detDataGridView[e.ColumnIndex, e.RowIndex];
                  dgcbm.DataSource = modulosBindingSource;
                  this.filteredModulosBS.RemoveFilter();
              }
  
              if (e.ColumnIndex == this.ComboBoxColumnTurma.Index)
              {
                  DataGridViewComboBoxCell dgcbt = (DataGridViewComboBoxCell)alunos_detDataGridView[e.ColumnIndex, e.RowIndex];
                  dgcbt.DataSource = turmasBindingSource;
                  this.filteredTurmasBS.RemoveFilter();
              }
          }
      }
  </code></pre>