private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
button2.Enabled = true;
Sheet_id= this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
sn.Text = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
brand.Text = this.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
model.Text = this.dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
num.Text = this.dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
colour.Text = this.dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
describe.Text = this.dataGridView1.SelectedRows[0].Cells[6].Value.ToString();
代码如上 我目的是要点击datagridview 控件获取每一行的第一列数据 但是发现一个问题就是 读取数据库后 dategridview 有了数据 还有一行标题栏 点击标题直接报错 System.ArgumentOutOfRangeException:“索引超出范围。必须为非负值并小于集合大小。
Arg_ParamName_Name” 点击数据没有问题 点击标题栏就是这 请问什么原因呢
还有有什么优化的代码吗 可以实现这个功能