Thread: argument outofrange exception unhandled

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    222

    Question argument outofrange exception unhandled

    hi all


    Argument OutOfRangeException was unhandled by user code
    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    Code:
    if (cChkBoxState == CheckBoxState.CheckedNormal)
                        {
                            string nodeFullPath = nodePath(this.tvFolders.SelectedNode.FullPath.ToString());
                            ListViewItem selectedItem = new ListViewItem();
                            selectedItem = e.Item;
                            string keyType = selectedItem.SubItems[1].Text.ToString();
    
                            InitListView(this.tvFolders.SelectedNode);
                            if ("STRING" == keyType)
                            {
                                ManagedRegItemString attributeRegItem = new ManagedRegItemString();
                                string stringVal = selectedItem.SubItems[2].Text.ToString();
                                attributeRegItem.stringValue = stringVal;
                                attributeRegItem.name = selectedItem.Text;
                                attributeRegItem.attributes = RegItemAttributeEnum.RegItemAttrReadonly;
                                ManagedRegistry.Delete(nodeFullPath, selectedItem.Text);
                                ManagedRegistry.WriteItem(nodeFullPath, attributeRegItem);
                                                                                        
                            }
                            if ("INTEGER" == keyType)
                            {
                                ManagedRegItemInteger attributeRegItem = new ManagedRegItemInteger();
                                string intVal = selectedItem.SubItems[2].Text.ToString();
                                int integerVal = (int)Convert.ToInt32(intVal);
                                attributeRegItem.integerValue = integerVal ;
                                attributeRegItem.name = selectedItem.Text;
                                attributeRegItem.attributes = RegItemAttributeEnum.RegItemAttrReadonly;
                                ManagedRegistry.Delete(nodeFullPath, selectedItem.Text);
                                ManagedRegistry.WriteItem(nodeFullPath, attributeRegItem);
                                                           
                            }
                            if ("BINARY" == keyType)
                            {
                                ManagedRegItemBinary attributeRegItem = new ManagedRegItemBinary();
                                string binVal = selectedItem.SubItems[2].Text.ToString();
                                byte [] binaryVal = new byte[10];
                                for(int i = 0; i < 10; i++)
                                {
                                binaryVal = System.Text.UTF8Encoding.ASCII.GetBytes(binVal);
                                }
                                attributeRegItem.binaryValue = binaryVal;
                                attributeRegItem.name = selectedItem.Text;
                                attributeRegItem.attributes = RegItemAttributeEnum.RegItemAttrReadonly;
                                ManagedRegistry.WriteItem(nodeFullPath, attributeRegItem);                           
                                
                            }
                            // Delete and write the updated value to the database
                            InitListView(this.tvFolders.SelectedNode);
                            EnumerateHBRegNode(this.tvFolders.SelectedNode);
                            
                            this.lvFiles.Refresh();
                            
             
                        }
    
                        ((CustomCheckBox)aChkBoxArray[e.ItemIndex]).bStateChanged = false;
                    }

    the exception occurs at this line below:

    ((CustomCheckBox)aChkBoxArray[e.ItemIndex]).bStateChanged = false;

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Then I'd guess that e.ItemIndex is either negative, or larger than aChkBoxArray.Length. Neither is good. Debug it.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 3
    Last Post: 11-11-2006, 06:46 PM
  3. Unhandled exception error in VC++
    By tandirovic in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2005, 05:16 PM
  4. unhandled exception error
    By trends in forum C++ Programming
    Replies: 4
    Last Post: 11-15-2002, 06:54 PM
  5. Unhandled Exception
    By StringQuartet13 in forum C++ Programming
    Replies: 1
    Last Post: 03-04-2002, 05:18 PM