Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取文本框的值,并将其放入不同形式的datagridview中#_C#_.net_Winforms_Visual Studio_Datagridview - Fatal编程技术网

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

C# 获取文本框的值,并将其放入不同形式的datagridview中#,c#,.net,winforms,visual-studio,datagridview,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;

我在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();
您有什么可以提供反馈或解决方案吗?

我无法发表评论

从Form2 cunstroctor参数中删除“字符串用户”或从form1发送它

我无法发送注释


从Form2 cunstroctor参数中删除“字符串用户”或从form1发送它

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

您似乎正在发送5个值,Form2希望收到6个值。您没有收到此(字符串用户)我以前使用(字符串用户)来显示登录过程的用户名。我不确定我是否理解您的意思,但如果您发送5个值,您必须收到5个值。请尝试不使用此字符串用户,如果您想要此字符串用户,然后需要在Form2中再添加一个输入参数。FormLogin,Form1,Form2。FormLogin我用来登录。成功登录后,用户名将显示在Form1上。和用于显示用户名的字符串User。它已经成功了,但让我困惑的是如何将值显示到form1上的文本框到form2Dude上的datagridview,您必须再次将其传递到form2或发布您的整个代码,并将给您更正的一个。看起来您发送了5个值,form2希望收到6个值。您没有收到这个(字符串用户)我使用的是(字符串用户)之前显示登录过程的用户名。我不确定我是否理解您的意思,但如果您发送5,则必须接收5。请尝试不使用此字符串用户,如果您需要此字符串用户,则需要在Form2中添加一个输入参数Verall i have 3 form。FormLogin,Form1,Form2。FormLogin我用来登录。成功登录后,用户名将显示在Form1上。和用于显示用户名的字符串User。它已经成功了,但让我困惑的是如何将form1上的文本框的值显示到form2Dude上的datagridview,您必须再次将其传递到form2,或者发布您的全部代码,并将给您更正的一个。总的来说,我有3个表单。FormLogin,Form1,Form2。FormLogin我用来登录。成功登录后,用户名将显示在Form1上。和用于显示用户名的字符串User。它已经成功了,但让我困惑的是,如何将form1上的文本框的值显示为Form2上的datagridview。现在,您收到了错误消息“不包含接受5个参数的构造函数”,这是因为在Form2中定义了6个参数。如果要在整个应用程序中保存登录的用户名,无需将其发送到每个表单,只需将它保存在一个静态变量中,并通过调用Static vartotal在其他表单中获得它。我有3个表单。FormLogin,Form1,Form2。FormLogin我用来登录。成功登录后,用户名将显示在Form1上。和用于显示用户名的字符串User。它已经成功了,但让我困惑的是,如何将form1上的文本框的值显示为Form2上的datagridview。现在,您收到了错误消息“不包含接受5个参数的构造函数”,这是因为在Form2中定义了6个参数。如果要在整个应用程序中保存登录的用户名,无需将其发送到每个表单,只需将其保存在一个静态变量中,并通过调用Static var以其他形式获得它