2014-03-30 41 views
0

編譯我的網格視圖以顯示一組訂單時,我得到索引超出範圍異常。c#>索引超出範圍。必須是非負數並且小於集合的大小

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

任何幫助,非常感謝。

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); 
       } 
+2

在你得到什麼線異常? –

+0

你的datagridview中有沒有行? – Steve

+0

你有多少個預定義的行,你有郵件嗎? – Dunken

回答

0

在循環插入一個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(); 
相關問題