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

C# 选择datagridview行值并将其传递给另一个窗体

C# 选择datagridview行值并将其传递给另一个窗体,c#,datagridview,C#,Datagridview,在我的应用程序中,我想在datagridview中选择一整行,并将其传递给位于另一个表单中的组合框。我用下面的代码进行了尝试,但它向我抛出了错误“this”方法不重载1个参数 这是我的密码 if(dataGridView1.SelectedCells.Count > 0) { var oneCell = dataGridView1[0]; int editloannumber = int.Parse(dataGridView1.Rows[oneCell.RowIndex].

在我的应用程序中,我想在datagridview中选择一整行,并将其传递给位于另一个表单中的组合框。我用下面的代码进行了尝试,但它向我抛出了错误“this”方法不重载1个参数

这是我的密码

if(dataGridView1.SelectedCells.Count > 0)
{
    var oneCell = dataGridView1[0];
    int editloannumber = int.Parse(dataGridView1.Rows[oneCell.RowIndex].Cells[0].Value.ToString());
    int editlid = int.Parse(dataGridView1.Rows[oneCell.RowIndex].Cells[8].Value.ToString());
    string editloantype = dataGridView1.Rows[oneCell.RowIndex].Cells[1].Value.ToString();
    string editneworsecond = dataGridView1.Rows[oneCell.RowIndex].Cells[2].Value.ToString();
    string editpurpose = dataGridView1.Rows[oneCell.RowIndex].Cells[11].Value.ToString();
    string editstatus = dataGridView1.Rows[oneCell.RowIndex].Cells[3].Value.ToString();
    string editcomments = dataGridView1.Rows[oneCell.RowIndex].Cells[7].Value.ToString();
    string editretail = dataGridView1.Rows[oneCell.RowIndex].Cells[12].Value.ToString();

    wartif_UW.editform e2 = new wartif_UW.editform(editloannumber, editloantype, editneworsecond, editpurpose, editstatus, editcomments, editretail,editlid);
    e2.ShowDialog();
 }
这是我的第二个表单构造函数

public editform(int editln, string edittype, string editno2, string purpo, string stat, string come,string reti,int lid)
    {
        InitializeComponent();
        comboload();

        loannumbertxtbox.Text  = editln ;
        loantypecombobox.Text = edittype;
        loanpurposrcombo.Text = purpo;
        neworseccombobox.Text = editno2;
        retailregcombo.Text = reti;
        statuscombbox.Text = stat;
        commnetrichtext.Text = come;
    }

DataGridView没有索引器。你必须这样做:

if (dataGridView1.SelectedCells.Count > 0)
        {
            var oneCell = dataGridView1.SelectedCells[0];
            int editloannumber = int.Parse(dataGridView1.Rows[oneCell.RowIndex].Cells[0].Value.ToString());
            int editlid = int.Parse(dataGridView1.Rows[oneCell.RowIndex].Cells[8].Value.ToString());
            string editloantype = dataGridView1.Rows[oneCell.RowIndex].Cells[1].Value.ToString();
            string editneworsecond = dataGridView1.Rows[oneCell.RowIndex].Cells[2].Value.ToString();
            string editpurpose = dataGridView1.Rows[oneCell.RowIndex].Cells[11].Value.ToString();
            string editstatus = dataGridView1.Rows[oneCell.RowIndex].Cells[3].Value.ToString();
            string editcomments = dataGridView1.Rows[oneCell.RowIndex].Cells[7].Value.ToString();
            string editretail = dataGridView1.Rows[oneCell.RowIndex].Cells[12].Value.ToString();

            wartif_UW.editform e2 = new wartif_UW.editform(editloannumber, editloantype, editneworsecond, editpurpose, editstatus, editcomments, editretail, editlid);
            e2.ShowDialog();
        }

你能发布editform的代码吗?当然我更新了我的问题:对不起,有人在我更新时编辑了它。我再次更新了我的问题哪一行抛出了错误。。?组合载荷;您的错误如果是此错误,则希望您使用至少一个参数调用它,您能否显示comboload的外观..?行中的错误:var oneCell=dataGridView1[0];DataGridView不是集合/索引类型。试试这个:var oneCell=datagridview.CurrentCell;谢谢你的回答,先生