【发布时间】:2014-05-15 06:02:32
【问题描述】:
我正在尝试制作一个多表单应用程序,该应用程序采用表属性的 DataGridView 并在单击按钮时将它们显示在 DetailView 中。当我单击按钮并打开第二个表单时,它是空的。然后,如果我关闭第二个表单,我会得到“发生‘System.NullReferenceException’类型的未处理异常”。这是我的代码:
表格一
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MultiForm
{
public partial class Form1 : Form2
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'personnelDataSet.employee' table. You can move, or remove it, as needed.
this.employeeTableAdapter.Fill(this.personnelDataSet.employee);
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDetails_Click(object sender, EventArgs e)
{
Form2 dForm = new Form2();
dForm.ShowDialog();
this.tableAdapterManager.UpdateAll(this.personnelDataSet);
}
}
}
表格 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MultiForm
{
public partial class Form2 : Form
{
//public Form2()
//{
// InitializeComponent();
//}
private void employeeBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.employeeBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.personnelDataSet);
}
private void Form2_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'personnelDataSet.employee' table. You can move, or remove it, as needed.
this.employeeTableAdapter.Fill(this.personnelDataSet.employee);
}
}
}
我在this.tableAdapterManager.UpdateAll(this.personnelDataSet); 收到表格 1 的例外情况,我们将不胜感激。
【问题讨论】:
标签: c# datagridview detailsview