首页上一页 1 下一页尾页 1 条记录 1/1页
dataGridView
发表在C#图书答疑
2010-11-07
是否精华
是
否
版块置顶:
是
否
你好,我在dataGridView的cellsclick事件中这样写:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > 0)
{
txtWork.Text=dataGridView1.SelectedCells[0].Value.ToString();
txtDept.Text = dataGridView1.SelectedCells[1].Value.ToString();
txtname.Text = dataGridView1.SelectedCells[2].Value.ToString();
comset.Text = dataGridView1.SelectedCells[3].Value.ToString();
txtAddress.Text = dataGridView1.SelectedCells[4].Value.ToString();
txtpay.Text = dataGridView1.SelectedCells[5].Value.ToString();
txtzhiwei.Text = dataGridView1.SelectedCells[6].Value.ToString();
}
但是报错,说“索引超出范围。必须为非负值并小于集合大小。参数名:index”
请问我应该如何解决这个问题呢?
谢谢!
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > 0)
{
txtWork.Text=dataGridView1.SelectedCells[0].Value.ToString();
txtDept.Text = dataGridView1.SelectedCells[1].Value.ToString();
txtname.Text = dataGridView1.SelectedCells[2].Value.ToString();
comset.Text = dataGridView1.SelectedCells[3].Value.ToString();
txtAddress.Text = dataGridView1.SelectedCells[4].Value.ToString();
txtpay.Text = dataGridView1.SelectedCells[5].Value.ToString();
txtzhiwei.Text = dataGridView1.SelectedCells[6].Value.ToString();
}
但是报错,说“索引超出范围。必须为非负值并小于集合大小。参数名:index”
请问我应该如何解决这个问题呢?
谢谢!