Results 1 to 3 of 3

Thread: [02/03] An unhandled exception of type ...

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    14

    Unhappy [02/03] An unhandled exception of type ...

    Code:
    An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    
    Additional information: Index and length must refer to a location within the string.
    I keep getting this error and I don't know why.

    It happens each time I click one of the lower items of one of my Comboboxes.

    The combobox items are added via a script that runs on Form1_Load which adds the nodes of an xml file into the combobox.

    The script for my combobox is as follows:
    VB Code:
    1. Private Sub OreDrop_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles OreDrop.SelectionChangeCommitted
    2.  
    3.         OreInfo.Text = OreDrop.SelectedText.ToString
    4.  
    5.     End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] An unhandled exception of type ...

    You misunderstand what the SelectedText property is for. It is to be used when the DropDownStyle is DropDown and the user has selected only part of the text displayed in the control, like in a TextBox. In the screenshot below the SelectedText would be "llo W". You should be using code like this:
    VB Code:
    1. OreInfo.Text = OreDrop.GetItemText(OreDrop.SelectedItem)
    Attached Images Attached Images  
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    14

    Re: [02/03] An unhandled exception of type ...

    Thank you! It works now.
    Greatly appreciate your help.

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