BindingNavigator add button is disabled

BindingNavigator add button is disabled

Old forum URL: forums.lhotka.net/forums/t/4612.aspx


triplea posted on Thursday, April 03, 2008

I 've never used this control with a CSLA object so apologies if this is obvious. I have a DataGridView and a BindingNavigator control on a form. Also 2 BindingSources. My object model is something like

Invoice (EditableRoot)
InvoiceLines (EditableChildList)
InvoiceLine (EditableChild)

So bindingSource 1 has Invoice as its datasource and bindingSource2 has Invoice.InvoiceLines as its datasource (using bindingSource1 as its data source and setting the DataMember to InvoiceLines).
I bind the grid and the bindingNavigator to bindingSource 2 and all works fine. But the add button is disabled. Of course this is because my child InvoiceLines only has a get and no set. How do you usually go about this? Or am I doing something fundamentally wrong?

JonnyBee replied on Friday, April 04, 2008

The add button is disabled because your bindingsource has "AllowNew" property set to false (default). You must set this property to true.

And in your InvoiceLineList you will need to override the AddNewCore method with something like this code:


        protected override object AddNewCore() {
            InvoiceLine line =  InvoiceLine.NewEditableChild();
            this.Add(line);
            return line;
        }
This is necessary because the CSLA business objects does not expose a public constructor - and thus requires you to call the static NewEditableChild method and add the new object to your list.

/jonny

triplea replied on Friday, April 04, 2008

Thanks Jonny that worked fine.

Copyright (c) Marimer LLC