I'm getting this exception when trying to select the new item added to a listbox via its bindingsource.
This is the BindingSource with a DataSource of custom objects
BindingSource bs = new BindingSource() { DataSource = myObjectsList };
listbox.DataSource = bs;
listbox.DisplayMember = "MyObjectProperty";
When i add a new item to the BindingSource the listbox updates but i can't select the new item
bs.Add(new MyObject());
int newItemIndex = listbox.Items.Count - 1; // this returns the right index of the new added item
listbox.SelectedIndex = newItemIndex;
Here i get the System.ArgumentOutOfRangeException (InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.)
If i disable debug breaking in System exceptions the program goes on and the item get selected, but i can't understand why i'm getting that error if the listbox actually has the item.