我的应用程序出错...索引列negativecsome帮助? [英] Error in my app...index column negativecsome help?

查看:86
本文介绍了我的应用程序出错...索引列negativecsome帮助?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

+		$exception	{"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}	System.ArgumentOutOfRangeException





错误在这里





Error is here

row = (DataGridViewRow)roba_uslugeDataGridView.SelectedRows[i].Clone();
               int intColIndex = 0;





一些帮助吗?



什么我试过了:





Some help?

What I have tried:

private void roba_uslugeDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = new DataGridViewRow();

            for (int i = 0; i < roba_uslugeDataGridView.Rows.Count; i++)
            {

                


                row = (DataGridViewRow)roba_uslugeDataGridView.SelectedRows[i].Clone();
                int intColIndex = 0;
               
                foreach (DataGridViewCell cell in roba_uslugeDataGridView.SelectedRows[i].Cells)
                {


                    var ColIndex = dataGridView1.Rows.Add();
                    dataGridView1.Rows[intColIndex].Cells["redni_broj"].Value = intColIndex + 1;
                    dataGridView1.Rows[intColIndex].Cells["bar_kod"].Value = cell.Value.ToString();
                    dataGridView1.Rows[intColIndex].Cells["sifra"].Value = cell.Value;
                    dataGridView1.Rows[intColIndex].Cells["naziv_artikla"].Value = cell.Value;
                    dataGridView1.Rows[intColIndex].Cells["cijena"].Value = cell.Value;
                    dataGridView1.Rows[intColIndex].Cells["kolicina"].Value = "1";


                    foreach (DataGridViewRow g1 in dataGridView1.Rows)
                    {


                        g1.Cells["ukupno"].Value = (Convert.ToDouble(g1.Cells["kolicina"].Value) * Convert.ToDouble(g1.Cells["cijena"].Value)).ToString("0.00");

                    }


                    row.Cells[intColIndex].Value = cell.Value;
                    intColIndex++;
                }
                dataGridView1.Rows.Add(row);
            }
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.Refresh();

        }

推荐答案

exception {指数超出范围。必须是非负数且小于集合的大小。\\\\ n参数名称:索引} System.ArgumentOutOfRangeException
exception {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"} System.ArgumentOutOfRangeException





错误在这里





Error is here

row = (DataGridViewRow)roba_uslugeDataGridView.SelectedRows[i].Clone();
               int intColIndex = 0;





一些帮助吗?



什么我试过了:





Some help?

What I have tried:

private void roba_uslugeDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = new DataGridViewRow();

            for (int i = 0; i < roba_uslugeDataGridView.Rows.Count; i++)
            {

                


                row = (DataGridViewRow)roba_uslugeDataGridView.SelectedRows[i].Clone();
                int intColIndex = 0;
               
                foreach (DataGridViewCell cell in roba_uslugeDataGridView.SelectedRows[i].Cells)
                {


                    var ColIndex = dataGridView1.Rows.Add();
                    dataGridView1.Rows[intColIndex].Cells["redni_broj"].Value = intColIndex + 1;
                    dataGridView1.Rows[intColIndex].Cells["bar_kod"].Value = cell.Value.ToString();
                    dataGridView1.Rows[intColIndex].Cells["sifra"].Value = cell.Value;
                    dataGridView1.Rows[intColIndex].Cells["naziv_artikla"].Value = cell.Value;
                    dataGridView1.Rows[intColIndex].Cells["cijena"].Value = cell.Value;
                    dataGridView1.Rows[intColIndex].Cells["kolicina"].Value = "1";


                    foreach (DataGridViewRow g1 in dataGridView1.Rows)
                    {


                        g1.Cells["ukupno"].Value = (Convert.ToDouble(g1.Cells["kolicina"].Value) * Convert.ToDouble(g1.Cells["cijena"].Value)).ToString("0.00");

                    }


                    row.Cells[intColIndex].Value = cell.Value;
                    intColIndex++;
                }
                dataGridView1.Rows.Add(row);
            }
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.Refresh();

        }


简单:并非所有行都被选中。

i 从0到DGV中的行数不等。除非选择了所有行,否则它将始终大于SelectedRows集合中的项目数,并且您将始终获得异常。
Simple: not all rows are selected.
i varies from 0 to the number of rows in the DGV. Unless all rows are selected, this will always be larger than the number of items in the SelectedRows collection and you will always get an exception.


这篇关于我的应用程序出错...索引列negativecsome帮助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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