错误:“索引1没有值”怎么解决? [英] Error: "index 1 does not have a value" how to fix it?

查看:101
本文介绍了错误:“索引1没有值”怎么解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击datagridview包含数据时出错......(行,单元格,标题)



我不明白错误!



我认为问题在下面的代码中...



Error when click on datagridview contain data...(Row, Cells, Header)

I don''t understand error!

I think problem is here in the below code...

private void CreateTable(DataGridView grdvTest, ref DataTable table)
        {
            if (dgvResults.CurrentRow.Cells[1].Value != null)
            {
                int num = 0;
                while (num < grdvTest.ColumnCount)
                {
                    table.Columns.Add(grdvTest.Columns[num].HeaderText);
                    num++;
                }
                foreach (DataGridViewRow row in (IEnumerable)grdvTest.Rows)
                {
                    DataRow row2 = table.NewRow();
                    for (num = 0; num < row.Cells.Count; num++)
                    {
                        //row2[num] = (row.Cells[num].Value != null) ? row.Cells[num].Value.ToString().Replace(" ", " ") : "";
                        if (row.Cells[num].Value != null)
                            row2[num] = row.Cells[num].Value.ToString().Replace(" ", " ");
                        else
                            row2[num] = "";
                    }
                    table.Rows.Add(row2);
                }
            }





我的应用:搜索google =>填充到datagridview =>点击=>错误!



请帮忙!



这里我的项目用C#: http://www.mediafire.com/download.php?g7vtz2973g4h59r



关注!

推荐答案

尝试调试并单步执行源代码。

它应该引导你到达实际可行的行抛出错误。



请注意,问题可能不在同一行,而在于填充此数据的方式。
Try debugging and stepping through your source code.
It should lead you to the line that could actually be throwing the error.

Note that the problem could not be in the same line but in the way you are populating this data.


这篇关于错误:“索引1没有值”怎么解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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