C#datagridview保存空白记录 [英] C# datagridview saving blank records

查看:155
本文介绍了C#datagridview保存空白记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VS 2015 Professional中开发一个C#WinForms解决方案。在我的表单上,我有一个DataGridView没有正确保存行。输入数据并保存后,它会保存空白单元格。这是在我实现下面的代码后开始发生的。感谢您的时间和帮助。谢谢!



我的尝试:



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:

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();
       }
   }

推荐答案

你是否在 tbl_alunos_subDataGridView_CellEndEdit 方法,并逐步查看代码以查看发生了什么?



我还会包含 e.RowIndex if语句中的,以确保您保存已编辑的单元格所在的行。
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.


这篇关于C#datagridview保存空白记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆