C#datagridview保存空白记录

编程入门 行业动态 更新时间:2024-10-16 16:25:56
本文介绍了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 == thisboBoxModulo.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保存空白记录

本文发布于:2023-11-10 16:23:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575880.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空白   datagridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!