PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
ArgumentOutOfRangeException when toolstripmenuitem click-VBForums
Results 1 to 2 of 2

Thread: ArgumentOutOfRangeException when toolstripmenuitem click

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013

    ArgumentOutOfRangeException when toolstripmenuitem click

    Hello, I'm trying to pass a variable from main form to child form. The code below is giving me error:

    An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

    Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

    VB.NET Code:
    1. list = new List<string>();
    3. DataGridViewRow row = programs_dgv.Rows[programs_dgv.CurrentRow.Index];
    5. using (InsertData insertData = new InsertData())
    6. {
    7.     list[0] = row.Cells[2].Value.ToString();
    8.     list[1] = row.Cells[3].Value.ToString();
    9.     list[2] = row.Cells[4].Value.ToString();
    10.     list[3] = row.Cells[5].Value.ToString();
    11.     list[4] = row.Cells[6].Value.ToString();
    12.     list[5] = row.Cells[7].Value.ToString();
    13.     list[6] = row.Cells[8].Value.ToString();
    14.     list[7] = row.Cells[9].Value.ToString();
    15.     list[8] = row.Cells[10].Value.ToString();
    16.     list[9] = row.Cells[11].Value.ToString();
    17.     list[10] = row.Cells[12].Value.ToString();
    18.     list[11] = row.Cells[13].Value.ToString();
    19.     list[12] = row.Cells[14].Value.ToString();
    21.     insertData._list = list;
    23.     insertData.ShowDialog();
    24.     list = insertData.GetValues();
    25.     if (insertData.cancelRequested == true)
    26.     {
    27.         return;
    28.     }
    29. }
    I'm not a man of too many faces
    The mask I wear is one

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: ArgumentOutOfRangeException when toolstripmenuitem click

    Firstly, does this line actually make sense?
    csharp Code:
    1. DataGridViewRow row = programs_dgv.Rows[programs_dgv.CurrentRow.Index];
    Think about what that's doing. Why would you first get a row, then get the index of that row, then get the row at that index? Is it not obvious that you just end up with the same row that you started with?

    As for your issue, have you made any effort at to determine the cause.
    Index was out of range.
    Have you bothered to find out what the index was and what the range was? Do what you can for yourself first, then ask for help with what you can't.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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