Hi folks,
I am trying to insert the data into DataGridView and I am having this exception
"Index was out of range. Must be non-negative and less than the size of the collection."!
The code is
dgv_SearchResult.Rows[0].Cells[0].Value = (Object)myProfile.UserName.ToString();
dgv_SearchResult.Rows[0].Cells[1].Value = (Object)myProfile.Description.ToString();
dgv_SearchResult.Rows[0].Cells[2].Value = (Object)myProfile.Statistics.SubscriberCount.ToString();
dgv_SearchResult.Rows[0].Cells[3].Value = (Object)myProfile.Statistics.ViewCount.ToString();
Any idea why the exception is occuring?
Index was out of range: DataGridView
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Sam HobbsRank #108 · 20.5K reputationPosted Aug 18, 2010, 8:02 AM EDT
Farrukh Javeid38 reputationPosted Aug 18, 2010, 5:03 AM EDT
Object[] objArray = new Object[4];
objArray[0] = myProfile.UserName.ToString();
objArray[1] = myProfile.Description.ToString();
objArray[2] = myProfile.Statistics.SubscriberCount.ToString();
objArray[3] = myProfile.Statistics.ViewCount.ToString();
dgv_SearchResult.Rows.Add(objArray);
Warm Regards,
Farrukh Javeid