Results 1 to 19 of 19

Thread: Bound Combobox throws System.ArgumentOutOfRangeException

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2013
    Posts
    178

    Bound Combobox throws System.ArgumentOutOfRangeException

    I'm adding a combobox to a Winform and binding it to a dataset using the arrow menu on the combobox and stepping through the user interface. It auto populates the dataset, binding source and table adapter as normal. All of my comboboxes throw the same exception, but i'm not sure what is out of range:

    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll

    Does anyone have any insight to this?

  2. #2
    Lively Member GTDriver's Avatar
    Join Date
    Apr 2015
    Location
    Blighty
    Posts
    66

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    Can you share your code please?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2013
    Posts
    178

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    There's not any code, it's all done in the combobox menu. Click the small arrow on the upper right corner of the combobox and bind to a DataSet, select the Display Member, select the Value Member from the pull-down menus and run the application.

    This happens on every bound combobox in my application. The dataset populates the combobox values just fine, it just throws this first chance exception and I'm not sure why.
    Last edited by Fedaykin; Aug 5th, 2015 at 05:39 PM.

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    Quote Originally Posted by Fedaykin View Post
    There's not any code, it's all done in the combobox menu. Click the small arrow on the upper right corner of the combobox and bind to a DataSet, select the Display Member, select the Value Member from the pull-down menus and run the application.

    This happens on every bound combobox in my application. The dataset populates the combobox values just fine, it just throws this first chance exception and I'm not sure why.
    There has to be code, the tableadapters have to fill the datatables when the form loads. Look in the form_load event. Also, you put that code inside a Try/Catch block and maybe it will give you a better explanation of the error.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2013
    Posts
    178

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    Here is the auto-generated code from the binding the combobox. I added a Try Catch as suggested but it did not catch any exception, and yet a first chance exception was generated in the Immediate Window:

    Code:
    Private Sub Form81_AcctProjectCost_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'SalesEmpNameds.EmpName' table. You can move, or remove it, as needed.
            Try
                Me.EmpNameTableAdapter.Fill(Me.SalesEmpNameds.EmpName)
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
    
    
        End Sub

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    When does the exception occur? When you start the program, when the form load, when you click on the combobox. The IDE usually stops on the line of code causing the error.

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    This happens on every bound combobox in my application. The dataset populates the combobox values just fine, it just throws this first chance exception and I'm not sure why.
    So are all the comboboxes filled by the same datatable?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2013
    Posts
    178

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    The error occurs when the form loads, specifically when the Me.EmpNameTableAdapter.Fill(Me.SalesEmpNameds.EmpName) runs.
    No, all comboboxes are filled by various different datatables. The example I gave here is a very simple one. Like I said before the data loads into the combobox without any hitch and since this is a First chance exception the debugger doesn't stop it and a Try Catch doesn't catch it. It's very strange.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 2013
    Posts
    178

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    Okay the plot thickens:

    When I fill the combobox at form load this error:
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll

    When I close the form with a Me.Dispose() this error:
    A first chance exception of type 'System.Data.EvaluateException' occurred in System.Data.dll

    If I comment out the
    Code:
    Me.EmpNameTableAdapter.Fill(Me.SalesEmpNameds.EmpName)
    , then no error occurs.

    The dataset query that's embedded in the Edit Query UI in Visual Studio looks like this

    Code:
    SELECT wholename FROM dbo.EmpName WHERE Salesperson = 1
    I appreciate you guys helping me dial this in.

  10. #10
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    I don't have an answer for you but I would suggest a couple of things. When you post your code, post the actual code and not just part of it. So if there is more code in your Form_Load event post all of it. Also, there is no need for the Me.Dispose, if you want to manually close the form then us Me.Close.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jul 2013
    Posts
    178

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    Quote Originally Posted by wes4dbt View Post
    I don't have an answer for you but I would suggest a couple of things. When you post your code, post the actual code and not just part of it. So if there is more code in your Form_Load event post all of it. Also, there is no need for the Me.Dispose, if you want to manually close the form then us Me.Close.
    As I've repeatedly stated, there is no other code, the complete code is posted above in the formload event, the code is a single line auto-generated by Visual Studio when you bind the combobox. Both Me.Close and Me.Dispose yield the same result. Both errors are eliminated if I simply comment out the single line of code that fills the combobox.

    I only added the Try Catch to try to get more info about the error, but it doesn't catch anything.

  12. #12
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    No, all comboboxes are filled by various different datatables. The example I gave here is a very simple one.
    As I've repeatedly stated, there is no other code, the complete code is posted above in the formload event, the code is a single line auto-generated by Visual Studio when you bind the combobox.
    If there is more than one datatable then you have more code.

    Anyway, maybe someone else can figure out what's going on. Good luck

  13. #13
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    the only thing that comes to my mind is that maybe your combo doesn't have all of the values it's trying to bind to.
    Ex: the DT for the combo hold 1,3,5,6,7... but the record that it's trying to show has a value of 2 ... so it doesn't exist in the combo.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jul 2013
    Posts
    178

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    Quote Originally Posted by techgnome View Post
    the only thing that comes to my mind is that maybe your combo doesn't have all of the values it's trying to bind to.
    Ex: the DT for the combo hold 1,3,5,6,7... but the record that it's trying to show has a value of 2 ... so it doesn't exist in the combo.

    -tg
    That's what the error message 'System.ArgumentOutOfRangeException' would have me believe as well, but I'm not searching for a value before the query and everything present in the database ends up in the combobox.

    The other error message 'System.Data.EvaluateException' occurred in System.Data.dll when the form closes is equally baffling.

    If i comment out the combobox fill both error messages no longer appear, so that's definitely where its occurring. I'll try some other stuff to see if i can shake something loose. Thanks for everyone's responses.

  15. #15
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    I would suggest this first, move the code in the Form Load event to a separate sub and then call it with a button or something else. The reason I say this is because depending on your architecture configuration, for some reason, when an exception occurs in the load event it just jumps out without catching it.
    Last edited by kaliman79912; Aug 6th, 2015 at 04:40 PM.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  16. #16
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    Code:
    SELECT wholename FROM dbo.EmpName WHERE Salesperson = 1
    Are any of the properties for the combobox, like DisplayMember, ValueMember or SelectedValue set to any other than "wholename", sense that's the only column in the datatable? If they are set to anything that's not in the datatable that could throw an error.

  17. #17
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    Also, when you bind your control using the designer, you assign a data member and a value member (optional). Are you setting both? if so, what fields are you selecting for them?
    How about SelectedValue?
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  18. #18
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    Quote Originally Posted by Fedaykin View Post
    That's what the error message 'System.ArgumentOutOfRangeException' would have me believe as well, but I'm not searching for a value before the query and everything present in the database ends up in the combobox.

    The other error message 'System.Data.EvaluateException' occurred in System.Data.dll when the form closes is equally baffling.

    If i comment out the combobox fill both error messages no longer appear, so that's definitely where its occurring. I'll try some other stuff to see if i can shake something loose. Thanks for everyone's responses.
    You may not have written any code, but code was generated in the designer files that does the selection. That's where I suspect the problem might be...

    You can set breakpoints in the designer file, then step through it, see if the error happens in there.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19
    New Member
    Join Date
    Nov 2016
    Posts
    1

    Re: Bound Combobox throws System.ArgumentOutOfRangeException

    I realize this post is old but I figured others may have this issue and this may help. I had had the same issue...multiple "first chance exceptions" being thrown during the call to fill the dataset. Try the following:

    SomeBindingSource.SuspendBinding
    SomeTableAdapter.Fill(SomeTable)
    SomeBindingSource.ResumeBinding

    That keeps the control from doing work while you load data. Obviously you may need to do mulitple suspends then fills then resumes depending on your data. On some forms designs the exceptions caused no problems for me. But on one of my forms I had a self-referencing table (parent/child) with a combo box and the behavior was strange. Editing the first row in the dataset caused the combo to point to the first record regardless of the proper data while editing any other record would produce the correct behavior. Once I suspended, filled, and resumed the exceptions went away and everything worked properly.

    I hope someone finds this useful.

    Dennis

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