all groups > dotnet windows forms databinding > november 2007 >
You're in the

dotnet windows forms databinding

group:

Listbox bound to BindingList


Listbox bound to BindingList Jack Jackson
11/23/2007 1:54:26 PM
dotnet windows forms databinding:
VB2005. I have a ListBox bound to a BindingList that is initially
empty. As soon as I add an item to the BindingList, the call to Add
throws an exception:
InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.
Parameter name: SelectedIndex

The following code demonstrates this:

Dim xx As New System.ComponentModel.BindingList(Of String)

Me.ListBox1.DataSource = xx
xx.Add("aa")
xx.Add("bb")

The exception only occurs on the first add. If I swap the setting of
DataSource and the first Add, it works fine.

Re: Listbox bound to BindingList Jack Jackson
11/23/2007 3:50:18 PM
On Fri, 23 Nov 2007 13:54:26 -0800, Jack Jackson
[quoted text, click to view]

I just noticed that if I continue in the debugger, execution proceeds
to the next statement. Is that normal? I would expect my application
level exception handler to get control on any unhandled exception.

I also just noticed that I now have this same behavior with a combobox
in another app. Both of these used to not get exceptions, so I am
Re: Listbox bound to BindingList Jack Jackson
11/30/2007 10:43:53 AM
I'm not surprised you can't duplicate it. It just started happening
to me, and it happens in multiple projects. It happens in a new
project with the simple code I posted.

It certainly seems like something broke, and I can't imagine any
option that I changed that would cause this. I will try your
suggestions.

On Fri, 30 Nov 2007 18:13:53 +0100, "Morten Wennevik [C# MVP]"
[quoted text, click to view]
Re: Listbox bound to BindingList Morten Wennevik [C# MVP]
11/30/2007 6:13:53 PM
Hi Jack,

I'm afraid I can't reproduce your problem. Does this problem always occ=
ur, even in a blank solution with only a ListBox? Are you doing anythin=
g else you may think could interfere?

I have never encountered this error, and according to google, very few o=
thers as well. If you always get this error, try running the code outsi=
de visual studio and/or in release mode. It may be that Visual Studio h=
as gone corrupt, in which case you might need to reinstall it.



On Sat, 24 Nov 2007 00:50:18 +0100, Jack Jackson <jacknospam@pebbleridge=
[quoted text, click to view]



-- =

Happy coding!
AddThis Social Bookmark Button