Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.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# 如何通过单击数据网格在多个文本框中显示数据_C#_Datagrid - Fatal编程技术网

C# 如何通过单击数据网格在多个文本框中显示数据

C# 如何通过单击数据网格在多个文本框中显示数据,c#,datagrid,C#,Datagrid,我有一个数据网格和一些相同形式的文本框。我想通过点击数据网格来填充文本框。但它显示了这个错误:对象引用未设置为对象的实例。这是我的数据网格点击事件代码 if (e.RowIndex >= 0) { DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex]; textBox5.Text = row.Cells[0].Value.ToString();

我有一个数据网格和一些相同形式的文本框。我想通过点击数据网格来填充文本框。但它显示了这个错误:对象引用未设置为对象的实例。这是我的数据网格点击事件代码

        if (e.RowIndex >= 0)
        {
            DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
              textBox5.Text = row.Cells[0].Value.ToString();
            textBox1.Text = row.Cells[1].Value.ToString();
            textBox3.Text = row.Cells[2].Value.ToString();
            textBox4.Text = row.Cells[3].Value.ToString();
            textBox6.Text = row.Cells[4].Value.ToString();
            textBox7.Text = row.Cells[5].Value.ToString();
            textBox2.Text = row.Cells[6].Value.ToString();
        }

试试这个
DataGridViewRow行=dataGridView1.SelectedRows[0];textBox2.Text=row.Cells[0]。Value.ToString();textBox3.Text=row.Cells[1]。Value.ToString();textBox4.Text=row.Cells[2]。Value.ToString();textBox5.Text=row.Cells[3]。Value.ToString()显示此错误:索引超出范围。必须是非负数,并且小于集合的大小。我取5个文本框,我想你需要7个,所以添加它。