简体   繁体   English

从form2读取dataTable并在运行开始时将其发送到form 1

[英]Read dataTable from form2 and send it to form 1 at the start of running

I would like to get the data from table 2 in form 2 to form 1 to initialize some variables, so I made a method to return the specific value: 我想从表格2的表2到表格1的数据中初始化一些变量,所以我做了一个返回特定值的方法:

public String pass(int i, int j)
    {

            return editInfoDataGridView.Rows[j].Cells[i].Value.ToString();

    }

but there is an error: 但是有一个错误:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll mscorlib.dll中发生类型为'System.ArgumentOutOfRangeException'的未处理异常

Additional information: Index was out of range. 附加信息:索引超出范围。 Must be non-negative and less than the size of the collection. 必须为非负数并且小于集合的大小。

As I know that the data is always stored in the table so why it returns that error. 据我所知,数据始终存储在表中,因此为什么返回该错误。

You can use the properties for accessing the data one form into another. 您可以使用属性来将数据从一种形式转换为另一种形式。

For Example, If you have the table getting populated with some data on say Form A, add something like this in Form A... 例如,如果您的表中填充了一些数据,例如Form A,则在Form A中添加类似的内容...

public string ValueNeedToUse { get; set; }

Assign the required value in table to this property, 将表格中的所需值分配给该属性,

FirstName = this.sampleDBDataSet.BasicInfo[ColCount]["FirstName"].ToString();

Initialize your parent form ie Form A in second form say, Form B... 初始化您的父母表格,即第二种形式的表格A,例如表格B ...

public frmsecond(frmMain ImportedForm)
{
        InitializeComponent();
        strFirstName = ImportedForm.FirstName;
}

and That's it!! 就是这样!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM