IBindingList AllowNew is FALSE!!!

G

Guest

Hi Anyone,

I am beyond frustrated with the .NET databinding. I have custom business
objects and collections for each which implement the IBindingList interface
and inherit from the CollectionBase. Several of my business objects contain
collections of other business objects up to three or four levels deep. For
the most part they work perfectly but there is one case for which everything
goes haywire. When my objects are bound to listboxes and the collections are
empty the CurrencyManager keeps trying to call the AddNew method of the
IBindingList interface. I don't see how this is possible considering the
AllowNew property is set to false on all of my objects. I don't work in
datagrids so have no need to implement this portion of the interface. I need
help...

Thanks in advance,
Nathan
 
J

Justin Rogers

Get a full call-stack when your method is called and give us that. In general,
AddNew can be called irregardless of whether or not AllowNew is set. Calls
to AddNew on the CurrencyManager don't check for validity.
 
T

Thomas Tomiczek [MVP]

It is possible because - and now the fun starts - AddNew is called by the
binding infrastructure if the list is empty to create one intance on which
then reflection can be used to find out sub-instances.

Despite that this information should be available on an ITypedList
interface.

The added objects are then removed afterwards.

Live with it :) It is pretty hard ,though - whoever made the databinding
architecture should be beaten.

--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
(CTO PowerNodes Ltd.)
 
G

Guest

Here is one situation when AddNew is called. My listbox's are binding to the
empty collections.
neonms.dataobjects.dll!NeonMS.DataObjects.LetterSetCollection.AddNew() Line 116 + 0x1e bytes Basic
system.windows.forms.dll!System.Windows.Forms.CurrencyManager.AddNew() +
0x3d bytes

system.windows.forms.dll!System.Windows.Forms.RelatedCurrencyManager.ParentManager_CurrentChanged(System.Object
sender = {System.Windows.Forms.CurrencyManager}, System.EventArgs e =
{System.EventArgs}) + 0xd6 bytes

system.windows.forms.dll!System.Windows.Forms.RelatedCurrencyManager.RelatedCurrencyManager(System.Windows.Forms.BindingManagerBase
parentManager = {System.Windows.Forms.CurrencyManager}, string dataField =
"Letters") + 0x135 bytes

system.windows.forms.dll!System.Windows.Forms.BindingContext.EnsureListManager(System.Object
dataSource = {NeonMS.DataObjects.LetterSetCollection}, string dataMember =
"Letters") + 0x38a bytes

system.windows.forms.dll!System.Windows.Forms.BindingContext.get_Item(System.Object
dataSource = {NeonMS.DataObjects.LetterSetCollection}, string dataMember =
"Letters") + 0x15 bytes

system.windows.forms.dll!System.Windows.Forms.ListControl.SetDataConnection(System.Object
newDataSource = {NeonMS.DataObjects.LetterSetCollection},
System.Windows.Forms.BindingMemberInfo newDisplayMember =
{System.Windows.Forms.BindingMemberInfo}, bool force = false) + 0x1b8 bytes

system.windows.forms.dll!System.Windows.Forms.ListControl.set_DisplayMember(string value = "Letters.Name") + 0x58 bytes
NeonMS.WinApp.exe!NeonMS.WinApp.SetForm.BindFormFields() Line 857 + 0x1d
bytes Basic
NeonMS.WinApp.exe!NeonMS.WinApp.SetForm.SetForm_Load(Object sender =
{NeonMS.WinApp.SetForm}, System.EventArgs e = {System.EventArgs}) Line 813 +
0xa bytes Basic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top