获取文本框的值并将其放入datagridview中以不同的形式c#

时间:2016-06-08 08:48:01

标签: c# .net winforms visual-studio datagridview

我在Form1中有五个文本框和一个按钮,而不是我想在Form2中将值文本框发送到datagridview。尝试运行时,它将显示错误消息"不包含带有5个参数的构造函数" Form1的这段代码:

 private void button2_Click(object sender, EventArgs e)
    {
        string IdStudent = textBox1.Text;
        string NameStudent = textBox2.Text;
        string AddressStudent = textBox3.Text;
        string EmailStudent = textBox4.Text;
        string PhoneNumStudent = textBox5.Text;
        Form2 frm = new Form2(IdStudent,NameStudent,AddressStudent,EmailStudent,PhoneNumStudent);
        this.Close();

这段代码形式2:

public partial class Form2 : Form
{
    public Form2(String User, string IdStudent, string NameStudent, string AddressStudent, string EmailStudent, string PhoneNumStudent)

    {
        InitializeComponent();

        int row = 0;
        dataGridView1.Rows.Add();
        row = dataGridView1.Rows.Count - 2;
        dataGridView1["IdStudent", row].Value = IdStudent;
        dataGridView1["NameStudent", row].Value = NameStudent;
        dataGridView1["AddressStudent", row].Value = AddressStudent;
        dataGridView1["Email", row].Value = EmailStudent;
        dataGridView1["Phone", row].Value = PhoneNumStudent;
        dataGridView1.Refresh();

您可以提供任何反馈或解决方案吗?

2 个答案:

答案 0 :(得分:1)

我无法发送评论,

从Form2 cunstroctor参数中删除“String User”或从form1

发送它

答案 1 :(得分:1)

感谢您的反馈并提供解决方案。但我在以下链接中找到了我的问题的解决方案: this