对于C#我还是一个新手,所以请耐心等待。从Form2中的文本框写入Form1中的Datagridview
我有Form1与DataGridView
和Button
。此按钮打开Form2
。
Form2
包含TextBox
和Button
,其关闭Form2
。
我需要将TextBox
中的文本Form2
写入Form1中DataGridView
的第一个单元格中。在我正在开发的应用程序中,Form1
中的DataGridView
中已有其他数据。
我已经上传了Visual Studio 2010文件here。
编辑:
请看看这个截图:
这里是我使用的代码:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.dataGridView1.Rows[0].Cells[0].Value = textBox1.Text;
this.Close();
}
}
我似乎实例化一个新的Form1
,当我不想。
欣赏帮助。
请请勿将代码发布到第三方服务。将相关部分的源代码直接放入您的问题中。 –
你应该给你的表格命名。 – SLaks
Ondrej Ttucny:我添加了代码。 – user1580591