Multiform DataGridView and DetailView Issues

本文关键字:Issues DetailView and DataGridView Multiform | 更新日期: 2023-09-27 18:03:21

我试图使一个多形式的应用程序,需要表属性的DataGridView,并在单击按钮时在DetailView中显示它们。当我单击按钮,第二个表单打开时,它是空的。然后,如果我关闭第二种形式,我得到"一个未处理的异常类型"系统。得到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上得到了例外,任何帮助都会非常感激。

Multiform DataGridView and DetailView Issues

没有将数据组件拖到托盘中,duh…对不起家伙。