Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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# - Fatal编程技术网

C# 如何将字符串从一个窗体发送到另一个窗体上的datagridview?

C# 如何将字符串从一个窗体发送到另一个窗体上的datagridview?,c#,C#,如何将字符串值从一个form2发送到主窗体上的DataGridView1最后一行 实现这一点的简单方法是什么?您需要在窗口/窗体中使用一些属性。 大概是这样的: public class WinStringGen : *Window or Form* { ... string myStringValue = ""; private void save() { myStringValue = "value"; //set your value }

如何将字符串值从一个form2发送到主窗体上的
DataGridView1
最后一行


实现这一点的简单方法是什么?

您需要在窗口/窗体中使用一些属性。 大概是这样的:

public class WinStringGen : *Window or Form*
{
...
    string myStringValue = "";
    private void save()
    {
      myStringValue = "value"; //set your value
    }
    public string MyStringValue
    {
      get{return myStringValue;}//Contains your string
    }
...
}
WinStringGen win = new WinStringGen(); //init window
win.showDialog(); //open window. When this method is called, the code following it is not executed until after the dialog box is closed.

string myValue = win.MyStringValue; //get the value
现在您可以得到如下值:

public class WinStringGen : *Window or Form*
{
...
    string myStringValue = "";
    private void save()
    {
      myStringValue = "value"; //set your value
    }
    public string MyStringValue
    {
      get{return myStringValue;}//Contains your string
    }
...
}
WinStringGen win = new WinStringGen(); //init window
win.showDialog(); //open window. When this method is called, the code following it is not executed until after the dialog box is closed.

string myValue = win.MyStringValue; //get the value

您可以在将调用form1的事件中使用此选项:

form1.datagridview1.rows[form1.datagridview1.rows.count-1].cells[0].value = mystring;
其中
mystring
是要传递的字符串。

有关更多信息,请发表评论。

低质量问题。。。你试过什么?代码示例?