-
Aug 5th, 2015, 02:45 PM
#1
Thread Starter
Addicted Member
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?
-
Aug 5th, 2015, 02:54 PM
#2
Lively Member
Re: Bound Combobox throws System.ArgumentOutOfRangeException
Can you share your code please?
-
Aug 5th, 2015, 05:36 PM
#3
Thread Starter
Addicted Member
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.
-
Aug 5th, 2015, 08:30 PM
#4
Re: Bound Combobox throws System.ArgumentOutOfRangeException
Originally Posted by Fedaykin
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.
-
Aug 5th, 2015, 09:16 PM
#5
Thread Starter
Addicted Member
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
-
Aug 5th, 2015, 09:48 PM
#6
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.
-
Aug 5th, 2015, 09:49 PM
#7
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?
-
Aug 6th, 2015, 09:29 AM
#8
Thread Starter
Addicted Member
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.
-
Aug 6th, 2015, 09:57 AM
#9
Thread Starter
Addicted Member
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.
-
Aug 6th, 2015, 10:22 AM
#10
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.
-
Aug 6th, 2015, 11:13 AM
#11
Thread Starter
Addicted Member
Re: Bound Combobox throws System.ArgumentOutOfRangeException
Originally Posted by wes4dbt
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.
-
Aug 6th, 2015, 11:25 AM
#12
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
-
Aug 6th, 2015, 11:51 AM
#13
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
-
Aug 6th, 2015, 03:58 PM
#14
Thread Starter
Addicted Member
Re: Bound Combobox throws System.ArgumentOutOfRangeException
Originally Posted by techgnome
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.
-
Aug 6th, 2015, 04:27 PM
#15
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
-
Aug 6th, 2015, 04:41 PM
#16
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.
-
Aug 6th, 2015, 04:44 PM
#17
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
-
Aug 6th, 2015, 09:19 PM
#18
Re: Bound Combobox throws System.ArgumentOutOfRangeException
Originally Posted by Fedaykin
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
-
Nov 14th, 2016, 05:38 PM
#19
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|