C# 给 dataGridView 动态添加行,下面的代码,一直报错
C# 给 dataGridView 动态添加行,下面的代码,一直报错

DataGridViewRow dgvr = new DataGridViewRow();
foreach (DataGridViewColumn c in this.dataGridView2.Columns)
{
dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
}
dgvr.Cells[0].Value = 1;
dgvr.Cells[1].Value = "张三";
dgvr.Cells[2].Value = "深圳";
dgvr.Cells[3].Value = "张三";
dgvr.Cells[4].Value = "深圳";
this.dataGridView2.Rows.Add(dgvr);“System.InvalidOperationException”类型的第一次机会异常在 System.Windows.Forms.dll 中发生
在 System.Windows.Forms.Control.get_Handle()
在 System.Windows.Forms.Control.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Control.set_Visible(Boolean value)
在 System.Windows.Forms.DataGridView.LayoutScrollBars()
在 System.Windows.Forms.DataGridView.ComputeLayout()
在 System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut, Boolean computeVisibleRows, Boolean invalidInAdjustFillingColumns, Boolean repositionEditingControl)
在 System.Windows.Forms.DataGridView.ResetUIState(Boolean useRowShortcut, Boolean computeVisibleRows)
在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PreNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow& dataGridViewRow, Boolean changeIsInsertion)
在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCur线程 '<无名称>' (0x219c) 已退出,返回值为 0 (0x0)。
rentCell)
在 System.Windows.Forms.DataGridViewRowCollection.InsertInternal(Int32 rowIndex, DataGridViewRow dataGridViewRow, Boolean force)
在 System.Windows.Forms.DataGridViewRowCollection.InsertInternal(Int32 rowIndex, DataGridViewRow dataGridViewRow)
在 System.Windows.Forms.DataGridViewRowCollection.AddInternal(DataGridViewRow dataGridViewRow)
在 System.Windows.Forms.DataGridViewRowCollection.Add(DataGridViewRow dataGridViewRow)
...全文
相关推荐
C#中DataGridView动态添加行及添加列的方法
在实际开发中,我们可能需要根据不同的需求动态地添加或删除行和列,以适应变化的数据结构。下面我们将详细介绍如何在C#中实现`DataGridView`动态添加行和列的方法。
c# 中datagridView中删除行的经典操作
它提供了丰富的功能来显示、编辑、添加或删除数据。本文将详细介绍如何在 `DataGridView` 控件中实现删除行的功能,并通过具体的代码示例来解释其工作原理。
C#对DataGridView进行添加、修改、删除数据操作
### C# 对 DataGridView 进行添加、修改、删除数据操作在C#应用程序开发中,尤其是在涉及用户界面的项目中,DataGridView 控件被广泛应用于显示和管理数据表格。
C# DataGridView单元格中动态添加多个控件
这个主题“C# DataGridView单元格中动态添加多个控件”就涵盖了如何在`DataGridView`的单元格内部动态创建和管理多个控件。
datagridview添加一个合计行[实例美好实用版]
本实例将深入探讨如何在C#编程环境中利用`DataGridView`添加一个具有合计功能的行,使得用户可以直观地查看数据的总计值。下面我们将详细讲解实现这一功能的关键步骤和相关知识点。


