0

我正在获取用户输入的数据并尝试以我创建的另一种形式将它们添加到 datagridview,但是,我有一个

你调用的对象是空的。当我尝试添加我的第一行时,

这是下面的代码:

    monthTrans mt = new monthTrans();
    private void completeBtn_Click(object sender, EventArgs e)
    {
        var todayDate = DateTime.Now;
        //MessageBox.Show(todayDate.ToString());
        var transType = typeLabel.Text;
        var currencySelected = CurrencyList.Text;
        var amount = AmountText.Text;
        var currencyPrice = currencyPriceText.Text;
        var total = totalAmountText.Text;

        var monthlyData = mt.myData;

        monthlyData.Rows.Add(todayDate, transType, currencySelected, amount, currencyPrice, total);

        //open a new window
        mt.Parent = Parent;
        mt.StartPosition = FormStartPosition.CenterParent;
        if (mt.IsDisposed)
              mt = new monthTrans();
        mt.Show();
    }

错误出现在“monthlyData.Rows.Add.......”

顺便说一句,我在我的 datagridview 表单中添加了下面的代码,以便在该表单之外访问它:

    public DataGridView myData
    {
        get;
        set;
    }

感谢您的帮助

4

1 回答 1

0

尝试:

private DataGridView _mydata = new DataGridView();
public DataGridView myData
{
    get { return _mydata; }
    set { _mydata = value; } 
}
于 2013-07-15T17:06:24.110 回答