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

msrs_it posted on Tuesday, September 28, 2010


I'm using CSLA.NET 3.8.4

I have quotation object having Items collection as child object. An Individual Item object is also having a collection of attachments as a child object. In UI I used a separate form to add attachments to each and every Item.

When I tried to save the root object quotation, an unhandled exception is thrown stating that 'EditLevelMismatch' has occurred.


My Attactment form is called from quotation form and the code looks like below.

        private void ubtnAttachments_Click(object sender, EventArgs e)
            if (itemsUltraGrid.Selected.Rows.Count <= 0)
                MessageBox.Show("Please select the row to add attachments", "Item not selected.",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            int index = itemsUltraGrid.Selected.Rows[0].Index;
            FormAttachments formAttachments = new FormAttachments(_quotation.Items[index].QuotationAttachments);


And my formAttachment code on OK button follows

        private void ubtnOK_Click(object sender, EventArgs e)
            quotationAttachmentsBindingSource.RaiseListChangedEvents = false;
            UnbindBindingSource(quotationAttachmentsBindingSource, true, false);
            this.DialogResult = DialogResult.OK;

Cancel button code as follows

        private void ubtnCancel_Click(object sender, EventArgs e)
            quotationAttachmentsBindingSource.RaiseListChangedEvents = false;
            UnbindBindingSource(quotationAttachmentsBindingSource, false, false);
            this.DialogResult = DialogResult.Cancel;

When I click on save button on my quotation form the error was thrown as the stated above.



RockfordLhotka replied on Tuesday, September 28, 2010

Version 3.8 doesn't support the idea of having more than one bindingsource (I assume we're talking Windows Forms here) bound to an object graph at the same time.

So if you open a child window to edit a child object, you must first completely unbind the object graph from the original form's bindingsource.

CSLA 4 addresses this, allowing multiple bindingsource objects to bind to the same graph - though even in that case you must absolutely be sure to properly unbind the child bindingsource when done. It is your responsibility to do the unbinding, because as long as an object is bound, its edit level is elevated - and even when you unbind, you need to force the edit level down one, because Windows Forms will leave it elevated.

This is just the way Windows Forms works, and it complicates things quite a lot. The Using CSLA .NET 3.0 ebook discusses this in some detail.

But in the end, 3.8 doesn't support multiple bindingsource bindings against an object graph, and I suspect that's your issue.

msrs_it replied on Wednesday, September 29, 2010

Thanks Rocky.

Even though I tried to use the quotation object without child form [by using infragistics WinGrid control for hierarchical data support]. still it's raising the same error. I'll go through the suggested book and will do some manual work and come back to you for any doubts.



msrs_it replied on Friday, October 15, 2010

Hi Rocky,

As you said previously, Multiple binding sources causing problem in WinForms. And the another thing was I tried with the Infragistics Netadvantage UltraWinGird Control which supports multi Band. It's is also not solved my problem due the Known Issue with that control. Recent version of using those controls solved my problem.

Thanks & Regards


Copyright (c) Marimer LLC