【问题标题】:c# > Index was out of range. Must be non-negative and less than the size of the collectionc# > 索引超出范围。必须是非负数且小于集合的大小
【发布时间】:2014-03-30 16:47:11
【问题描述】:

编译我的网格视图以显示一组订单时出现索引超出范围异常。

它不会返回所有行。它只返回一行

非常感谢任何帮助。

 try
                {
                    oClient.Connect(oServer);
                    MailInfo[] infos = oClient.GetMailInfos();
                    Console.WriteLine(infos.Length);
                    for (int i = 0; i < infos.Length; i++)
                    {
                        MailInfo info = infos[i];
                        Mail oMail = oClient.GetMail(info);

                        dgView_Inbox.Rows[i].Cells[0].Value = oMail.From.ToString();
                        dgView_Inbox.Rows[i].Cells[1].Value = oMail.Subject.ToString();

                    }
                    oClient.Quit();


                }
                catch (Exception ep)
                {
                    Console.WriteLine(ep.Message);
                }

【问题讨论】:

  • 您在哪一行得到异常?
  • 你的datagridview中有行吗?
  • 预定义的行数和邮件数一样多吗?
  • 在 oClient.Quit(); 行后出现错误
  • datatgridview 包含两列(来自 ,subject)它是免费的。

标签: c# datagridview imap


【解决方案1】:

在循环中插入一个 Add 命令并使用它的索引:

int newrow = dgView.Rows.Add();
dgView_Inbox.Rows[newrow ].Cells[0].Value = oMail.From.ToString();
dgView_Inbox.Rows[newrow ].Cells[1].Value = oMail.Subject.ToString();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 2014-10-20
    相关资源
    最近更新 更多