【问题标题】:Multiform DataGridView and DetailView IssuesMultiform DataGridView 和 DetailView 问题
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 2017-10-02
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多