错误编辑按钮:-Index超出范围。必须是非负数且小于集合的大小。 [英] Error Edit Button:-Index was out of range. Must be non-negative and less than the size of the collection.

查看:84
本文介绍了错误编辑按钮:-Index超出范围。必须是非负数且小于集合的大小。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击编辑按钮时显示文本框中的数据(从datagridview中选择行数据)

错误:-Index超出范围。必须是非负数且小于集合的大小。

我的以下代码: -



i want to display data in textbox when i click edit button (selected row data from datagridview )
ERROR:-Index was out of range. Must be non-negative and less than the size of the collection.
My following code:-

private void button1_Click(object sender, EventArgs e)
       {
           int i;
           i = dataGridView2.SelectedCells[0].RowIndex;
           textBox10.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
           textBox11.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
           textBox12.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
           textBox13.Text = dataGridView1.Rows[i].Cells[4].Value.ToString();
           textBox14.Text = dataGridView1.Rows[i].Cells[5].Value.ToString();
           textBox15.Text = dataGridView1.Rows[i].Cells[6].Value.ToString();
           textBox16.Text = dataGridView1.Rows[i].Cells[7].Value.ToString();
           textBox17.Text = dataGridView1.Rows[i].Cells[8].Value.ToString();
           textBox18.Text = dataGridView1.Rows[i].Cells[9].Value.ToString();
           textBox19.Text = dataGridView1.Rows[i].Cells[10].Value.ToString();
           textBox20.Text = dataGridView1.Rows[i].Cells[11].Value.ToString();
           textBox21.Text = dataGridView1.Rows[i].Cells[12].Value.ToString();

       }

推荐答案

您正在从dataGridview2中选择行并将dataGridview1中的值分配给textboxes。所以请交叉检查dataGridview1和dataGridview2上的行和列
you are selecting rows form dataGridview2 and assigning values from dataGridview1 to textboxes.So please cross check rows and columns on both dataGridview1 and dataGridview2


这篇关于错误编辑按钮:-Index超出范围。必须是非负数且小于集合的大小。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆