在主窗体frmMain上设置DataGridView,名称:dgvEquipmentList,用于显示数据库中的数据,并在工具栏设一个button控件,名称toolStripButton5。在子窗体test上设置textbox控件,名称txtBH,显示DataGridView控件中的某一字段BH值。
主窗体代码如下: //创建工具栏响应
private void toolStripButton5_Click(object sender, EventArgs e)
{
toolStripMenuItem28_Click(sender, e);
}
//创建工具栏事件
private void toolStripMenuItem28_Click(object sender, EventArgs e)
{
if (dgvEquipmentList.RowCount > 1)
{
DataSet ds = oper.GetDataSetZC(dgvEquipmentList.SelectedCells[1].Value.ToString());
if (ds.Tables[0].Rows.Count > 0)
{
test pdf = new test();//创建子窗体对象
pdf.M_frmMain = this;
pdf.M_str_BH = dgvEquipmentList.SelectedCells[1].Value.ToString();
pdf.ShowDialog();//显示子窗体
}
else
{
MessageBox.Show("用户选择的数据不存在!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DataBindGridViewList();
} } }子窗体代码如下: BaseClass.Operation oper = new EquipmentMS.BaseClass.Operation();//创建数据连接对象
public frmMain M_frmMain = null;
public string M_str_BH = ""; public test()
{
InitializeComponent();
} private void test_Load(object sender, EventArgs e)
{
DataSet ds = oper.GetDataSetZC(M_str_BH);
txtBH.Text = ds.Tables[0].Rows[0]["BH"].ToString();
}
但是,子窗体中的txtBH控件,一直是空的,不显示值。请问,代码哪错了?
主窗体代码如下: //创建工具栏响应
private void toolStripButton5_Click(object sender, EventArgs e)
{
toolStripMenuItem28_Click(sender, e);
}
//创建工具栏事件
private void toolStripMenuItem28_Click(object sender, EventArgs e)
{
if (dgvEquipmentList.RowCount > 1)
{
DataSet ds = oper.GetDataSetZC(dgvEquipmentList.SelectedCells[1].Value.ToString());
if (ds.Tables[0].Rows.Count > 0)
{
test pdf = new test();//创建子窗体对象
pdf.M_frmMain = this;
pdf.M_str_BH = dgvEquipmentList.SelectedCells[1].Value.ToString();
pdf.ShowDialog();//显示子窗体
}
else
{
MessageBox.Show("用户选择的数据不存在!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DataBindGridViewList();
} } }子窗体代码如下: BaseClass.Operation oper = new EquipmentMS.BaseClass.Operation();//创建数据连接对象
public frmMain M_frmMain = null;
public string M_str_BH = ""; public test()
{
InitializeComponent();
} private void test_Load(object sender, EventArgs e)
{
DataSet ds = oper.GetDataSetZC(M_str_BH);
txtBH.Text = ds.Tables[0].Rows[0]["BH"].ToString();
}
但是,子窗体中的txtBH控件,一直是空的,不显示值。请问,代码哪错了?
传值方法看看 http://www.cnblogs.com/tomin/archive/2009/02/25/1397677.html
楼上说的修改,是什么意思?