0
我有2种形式添加行,Form1包含在DataGridView和按钮“添加”,Form2包含textboxs和按钮“保存”,C#从另一种形式
我要添加行,当添加按钮是出现窗口2点击,然后保存信息从form2在datagridview点击保存按钮时 这是我用于添加和保存按钮的代码,但是当我这样做时,它只保存从form1写入的信息(保存按钮没有如果不更新datagridview的话)
private void AddButton_Click(object sender, EventArgs e)
{
Form2 windowAdd = new Form2();
windowAdd.SetDesktopLocation(this.Location.X + this.Size.Width, this.Location.Y);
windowAdd.ShowDialog();
var frm2 = new Form2();
frm2.AddGridViewRows(textName.Text, textDescription.Text, textLocation.Text, textAction.Text);
textName.Focus();
this.stockData.Product.AddProductRow(this.stockData.Product.NewProductRow());
productBindingSource.MoveLast();
}
private void SaveButton_Click(object sender, EventArgs e)
{
productBindingSource.EndEdit();
productTableAdapter.Update(this.stockData.Product);
this.Close();
}
你的Add按钮的代码似乎启动窗口2的对话框(windowAdd) (你使用ShowDialog来显示它的Modal,所以用户必须关闭窗体才能继续移动,窗体将是空白的),然后你用Form1的Textboxes中的值显式地创建另一个form2(frm2)来调用看起来静态的AddGridViewRows方法。然后,将Focus设置为Form1.textName,然后向产品添加一行,并在数据源中添加MoveLast。这里有太多错误,很难知道从哪里开始。 –