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个,所以添加它。