Multiform DataGridView和DetailView问题

时间:2014-05-15 06:02:32

标签: c# datagridview detailsview

我正在尝试创建一个多表单应用程序,它接受表属性的DataGridView,并在单击按钮时在DetailView中显示它们。当我单击按钮并打开第二个表单时,它是空的。然后,如果我关闭第二个表单,我会得到'未处理的类型'System.NullReferenceException'发生'的异常。这是我的代码:

表格1

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上获得了例外情况。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

没有将数据组件拖入托盘中...对不起家伙。