我在将数据从一种表单传递到另一种表单时遇到问题。我已经看过几个例子并尝试过,但没有任何工作。Winforms在表单之间传递值问题
在“估计”的形式,这是什么打开“EstimateTakeoffItemAdd”表...
private void TakeoffGridAdd(object sender, FormClosingEventArgs e)
{
MessageBox.Show(AutoID.ToString());
int index = 0;
if (AutoID > 0)
{
}
}
private void addDialog()
{
if (treeView1.SelectedNode.Name.ToString() != "c")
{
using (var et = new EstimateTakeoffItemAdd(estID, Convert.ToInt32(treeView1.SelectedNode.Name.ToString()), Convert.ToInt32(SheetSelector.SelectedValue), Convert.ToInt32(BidItemSelector.SelectedValue), Convert.ToInt32(SortCodeSelector.SelectedValue)))
{
et.FormClosing += new FormClosingEventHandler(TakeoffGridAdd);
et.ShowDialog();
AutoID = et.AddedID;
}
}
}
在“EstimateTakeoffItemAdd”的形式,这是可以节省/关闭窗体的功能...
public int AddedID { get; set; }
public bool ItemAdded { get; set; }
private void radButton2_Click(object sender, EventArgs e)
{
pricemod = (Convert.ToDecimal(LaborText.Text) == dbLabor) ? 0 : 1;
pricemod = (Convert.ToDecimal(MaterialText.Text) == dbPrice) ? 0 : 1;
try
{
DBConnector db = new DBConnector();
db.query = "SELECT Auto_increment FROM information_schema.tables WHERE table_name='tb_estimate_takeoff'";
this.AddedID = Convert.ToInt32(db.executeScalar());
}
finally
{
try
{
DBConnector db = new DBConnector();
db.query = "INSERT INTO tb_estimate_takeoff (item, estimate, sheet, qty, hrs, mat, biditem, phase, matunit_mod, labunit_mod, guid) VALUES (" +
"'" + DescriptionText.Text + "', " +
estID + ", " +
sheet + ", " +
QtyText.Value + ", " +
LaborText.Text + ", " +
MaterialText.Text + ", " +
biditem + ", " +
phase + ", " +
pricemod + ", " +
labormod + ", " +
"'" + guid + "'" +
")";
db.executeNonQuery();
}
finally
{
ItemAdded = true;
this.Close();
}
}
}
我需要的是将AddedID恢复回主“估计”窗体。在关闭“EstimateTakeoffItemAdd”之前使用MessageBox我可以看到AddedID正在处理该表单,但它在“Estimate”表单上显示为0。
第二次打开对话框并关闭后,第一个AddedID随后可用于“估计”窗体。
我错过了什么?
看起来很好。 '但是它在“估计”表单上显示0。“< - 你能告诉我们你在哪里做这个?另外,当你在调试器中遍历你的代码,并且在'AutoID = et.AddedID'行查看'et.AddedID'的值时,你看到了什么? – sstan
通过使用FormClosing函数中的消息框...已在上面编辑。 – Mike
你可以编辑你的文章,而不是把它放在评论中?这样,它会有适当的格式,其他人也会看到它。谢谢! – sstan