CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2010
    Posts
    13

    Exclamation Index was out of range

    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?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

  3. #3
    Join Date
    Aug 2010
    Posts
    13

    Re: Index was out of range

    Figured out another way to perform this task. The code is as given below

    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

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Index was out of range

    Please mark your thread resolved.

    It is explained here :

    http://www.codeguru.com/forum/showthread.php?t=401115

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured