当前位置:编程学习 > C#/ASP.NET >>

winform窗体传值问题

        private void button1_Click(object sender, EventArgs e)
        {
            ModifySpecialty modifySpecialty;
            if (dataGrid1[dataGrid1.CurrentCell] != null)
            {
                modifySpecialty = new ModifySpecialty();
                modifySpecialty.textBox1.Text = ds.Tables[0].Rows[dataGrid1.CurrentRowIndex][0].ToString().Trim();
                //获得专业编号
                modifySpecialty.textBox2.Text = ds.Tables[0].Rows[dataGrid1.CurrentRowIndex][1].ToString().Trim();
                //获得专业名称
                modifySpecialty.richTextBox1.Text = ds.Tables[0].Rows[dataGrid1.CurrentRowIndex][2].ToString().Trim();
                //获得专业描述
                modifySpecialty.ShowDialog();
                //生成新窗体
            }
        }

上面的代码是朋友他写的管理系统里面的,在浏览窗口查询出记录,然后点击相应的记录,再点击修改按钮,即可弹出修改窗体,修改窗体中的各个文本框显示对应的值。这个过程其实很简单,但是在我自己写的代码里面就出了问题,大家看下面代码:

        private void btnAlter_Click(object sender, EventArgs e)
        {
            frmAlter alter = new frmAlter();
            alter.txtName.Text = ds.Tables[0].Rows[dgvList.CurrentRow.Index][1].ToString().Trim();
            alter.txtAge.Text = ds.Tables[0].Rows[dgvList.CurrentRow.Index][2].ToString().Trim();
            alter.cbSex.Text = ds.Tables[0].Rows[dgvList.CurrentRow.Index][3].ToString().Trim();
        }


然后报这个错:错误 1 “WindowsFormsApplication1.frmAlter.txtAge”不可访问,因为它受保护级别限制 D:\c#\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 98 19 WindowsFormsApplication1
错误 2 “WindowsFormsApplication1.frmAlter.cbSex”不可访问,因为它受保护级别限制 D:\c#\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 99 19 WindowsFormsApplication1
WinForm c# --------------------编程问答-------------------- WindowsFormsApplication1.frmAlter.txtAge 这个控件删了,重新拖一个。 --------------------编程问答-------------------- 还有cbSex呢 --------------------编程问答-------------------- txtAge的属性Modifiers改成Public
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,