[英]Index was out of range. Must be non-negative and less than the size of the collection. C#
[英]c# > Index was out of range. Must be non-negative and less than the size of the collection
編譯網格視圖以顯示一組訂單時,出現索引超出范圍異常。
它不會返回所有行。 只返回一行
任何幫助深表感謝。
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);
}
在循環中插入一個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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.