Click here to Skip to main content
15,917,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a C# WinForms Solution in VS 2015 Professional. In on my my forms, I have a DataGridView that is not correctly saving the rows. After I enter data and save, it saves blank cells. This started happening after I implemented the code below. I appreciate your time and help. Thank you!

What I have tried:

C#
private void Alunos_Load(object sender, EventArgs e)

       {
           this.tbl_cursosTableAdapter.Fill(this.bremingtonDataSet.tbl_cursos);
           this.tbl_modulosTableAdapter.Fill(this.bremingtonDataSet.tbl_modulos);
           this.tbl_turmasTableAdapter.Fill(this.bremingtonDataSet.tbl_turmas);
           this.tbl_alunosTableAdapter.Fill(this.bremingtonDataSet.tbl_alunos);
           this.tbl_alunos_subTableAdapter.Fill(this.bremingtonDataSet.tbl_alunos_sub);

           DataView dv = new DataView(bremingtonDataSet.Tables["tbl_modulos"]);
           filteredModulosBS.DataSource = dv;
      }

       private void tbl_alunos_subDataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
       {
           if (e.ColumnIndex == comboBoxModulo.Index)
           {
               DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)tbl_alunos_subDataGridView[e.ColumnIndex, e.RowIndex];
               dgcb.DataSource = filteredModulosBS;
               this.filteredModulosBS.Filter = "CodCurso=" + this.tbl_alunos_subDataGridView[e.ColumnIndex - 1, e.RowIndex].Value.ToString();
           }
       }

   private void tbl_alunos_subDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
   {
       if (e.ColumnIndex == this.comboBoxModulo.Index)
       {
           DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)tbl_alunos_subDataGridView[e.ColumnIndex, e.RowIndex];
           dgcb.DataSource = tblmodulosBindingSource;
           this.filteredModulosBS.RemoveFilter();
       }
   }
Posted
Updated 7-Oct-16 8:37am

1 solution

Did you put a breakpoint on the first line of the tbl_alunos_subDataGridView_CellEndEdit method, and step through the code to see what's happening?

I would also include e.RowIndex in the if statement to make sure you're saving the row that the edited cell was on.
 
Share this answer
 
v3
Comments
JC Carmo 7-Oct-16 14:52pm    
Sorry, I'm a newbie on C# so I don't really know how to do what you've suggested... But thank you for your feedback. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900