Question : BindingList(Of T) generate exception when replacing items

Hi experts,

I use BindingList(Of T) and when i want to replace a specific item in the list, i have an exception :

The list must be an IBindingList to AddNew

Here is the StackTrace :

   at System.Windows.Forms.CurrencyManager.AddNew()
   at System.Windows.Forms.RelatedCurrencyManager.ParentManager_CurrentItemChanged(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.CurrencyManager.OnCurrentItemChanged(EventArgs e)
   at System.Windows.Forms.RelatedCurrencyManager.ParentManager_CurrentItemChanged(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.CurrencyManager.OnCurrentItemChanged(EventArgs e)
   at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
   at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.FireListChanged(ListChangedType type, Int32 index)
   at System.ComponentModel.BindingList`1.SetItem(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.set_Item(Int32 index, T value)

I don't understand why because is some case, it works...

Thank you,

Regards.

1:
Me.DataSource.Item(index) = lRestoreMonitorDesign

Answer : BindingList(Of T) generate exception when replacing items

Dude are you trying to replace the object at ith position?

If yes, then you should better take that object@ith index into some object and work upon it.
binding list lets you upate/add/delete the object but you can't replace the object reference altogther
For doing this remove the requirec object and add a new one.

This is exactly the error says "The list must be an IBindingList to AddNew"

hope this helps :)
Random Solutions  
 
programming4us programming4us