C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-26-2008, 04:33 AM   #1
Registered User
 
Join Date: Nov 2008
Posts: 32
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;
leo2008 is offline   Reply With Quote
Old 11-26-2008, 05:20 AM   #2
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,769
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.
nvoigt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Screwy Linker Error - VC2005 Tonto C++ Programming 5 06-19-2007 02:39 PM
Unhandled exception on Stream variable for HttpWebRequest/HttpWebResponse BobS0327 C# Programming 3 11-11-2006 06:46 PM
Unhandled exception error in VC++ tandirovic Windows Programming 2 12-29-2005 05:16 PM
unhandled exception error trends C++ Programming 4 11-15-2002 06:54 PM
Unhandled Exception StringQuartet13 C++ Programming 1 03-04-2002 05:18 PM


All times are GMT -6. The time now is 11:56 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22