我遇到一个问题,我以与主窗体不同的形式检索方法中的值。
这是我的代码:
(这是我想要检索值的主要形式。)
private void EstimationComp_Click(object sender, EventArgs e)
{
PaintingFender pff = new PaintingFender();
textBox8.Text = panels;
textBox30.Text = amounts;
panels = pff.panel();
descr = pff.desc();
status = pff.stats();
amounts = pff.amount();
dtg.RowCount = 5;
dtg[0, 0].Value = panels;
dtg[1, 0].Value = descr;
dtg[2, 0].Value = status;
dtg[3, 0].Value = amounts;
}
这是我声明的方法的形式,当选择单选按钮时,我想从添加按钮检索值:
public string panel()
{
return p;
}
public string desc()
{
return d;
}
public string stats()
{
return s;
}
public string amount()
{
return a;
}
private void TADD_bump_Click(object sender, EventArgs e)
{
try
{
if ((conn == null) || (conn.State != ConnectionState.Open))
{
MessageBox.Show("unable to connect to database", "error");
return;
}
else
{
OleDbCommand cmd = new OleDbCommand("select * from p_painting");
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
da = new OleDbDataAdapter(cmd);
ds = new DataSet("ds");
da.Fill(ds);
ds.Tables[0].TableName = "table_mirror";
dtg.DataSource = ds.Tables["table_mirror"];
}
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
if (frontbumper.Checked == true)
{
status();
d = frontbumper.Text;
a = textBox2.Text;
p = "Fender";
if (bump_light.Checked == true)
{
s = "Light Repair";
}
if (bump_moderate.Checked == true)
{
s = "Moderate Repair";
}
if (bump_heavy.Checked == true)
{
s = "Heavy Repair";
}
if (bump_replacement.Checked == true)
{
s = "Replacement";
}
}
我跟踪了该方法,我认为单击按钮时它没有从按钮获取值,因为从程序开始就已经执行了该方法。我只想在单击按钮时执行该方法,以便我可以从 TADD 按钮检索值,以将字符串值传递到我的主窗体(即estimationcomp)中。
在您的主表单上创建一个公共字段。有房产就更好了。
在变量包含要共享的值的方法中设置此字段或属性。
现在从子表单实例引用父表单实例,您应该可以访问包含所需值的字段。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)