I'm having a problem when inserting a UserControl in a form. I drag my UserControl onto the form, save, and get the following screen:
I searched for SO and there is someone who had the same problem as me but I can't understand the answer or what to say with it.
I briefly show you the code and some indications so that you can guide me on the matter.
This is the UserControl and how it is bound:
The class that is bound to bsControl is the following:
namespace SmartInventorySystem.ViewModel.Controls
{
public class DispenseCartControlViewModel : FormViewModel
{
public DispenseCartControlViewModel()
{
ItemsToCheckout = new List<ItemToCheckoutRowViewModel>();
}
public List<ItemToCheckoutRowViewModel> ItemsToCheckout { get; set; }
public decimal SubTotal
{
get; //=> ItemsToCheckout.Sum(x => x.Quantity * x.UnitPrice);
set;
}
public decimal Discount { get; set; }
public decimal Vat { get; set; }
public decimal Total
{
get; //=> SubTotal - Discount + Vat > 0 ? (Vat / 100 * (SubTotal - Discount)) : 0;
set;
}
}
}
And finally, the code that has the control:
public partial class DispenseCartControl : UserControl, IDispenseCartView
{
private readonly DispenseCartPresenter _presenter;
public DispenseCartControl()
{
InitializeComponent();
_presenter = new DispenseCartPresenter(this);
State = new DispenseCartControlViewModel();
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DispenseCartControlViewModel State { get; set; }
public void ShowError(Exception ex)
{
MessageBox.Show(this, ex.Message, "Dispense Cart", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
public void ShowInfo(string msg)
{
MessageBox.Show(this, msg, "Dispense Cart", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public void UpdateFormBindingSource()
{
bsControl.ResetBindings(false);
}
private void DispenseCartControl_Load(object sender, EventArgs e)
{
bsControl.DataSource = State;
}
}
Update 1 : I add the call-stack where the designer throws me an error.
at System.Windows.Forms.BindToObject.CheckBinding() at System.Windows.Forms.BindToObject.SetBindingManagerBase(BindingManagerBase lManager) at System.Windows.Forms.Binding.SetListManager(BindingManagerBase bindingManagerBase) at System.Windows.Forms.ListManagerBindingsCollection.AddCore (Binding dataBinding) at System.Windows.Forms.BindingsCollection.Add(Binding binding) at System.Windows.Forms.BindingContext.UpdateBinding(BindingContext newBindingContext, Binding binding) at System.Windows.Forms.Control.UpdateBindings() at System. Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnParentBindingContextChanged EventArgs e) at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.set_BindingContextInternal(BindingContext value) at System.Windows.Forms.ContainerControl.set_BindingContext(BindingContext value) at System.Windows.Forms.ContainerControl. get_BindingContext() at System.Windows.Forms.Control.get_BindingContextInternal() at System.Windows.Forms.SplitContainer.get_BindingContext() at System.Windows.Forms.Control.get_BindingContextInternal() at System.Windows.Forms.Control.get_BindingContext( ) at System.Windows.Forms.Control.get_BindingContextInternal() at System.Windows.Forms.ContainerControl.get_BindingContext() at System.Windows.Forms.Control.get_BindingContextInternal() at System.Windows.Forms.ContainerControl.get_BindingContext() at System.Windows.Forms.Control.UpdateBindings( ) at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.ContainerControl.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control. CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows. Forms.Control.ControlCollection.Add(Control value) at System.Windows.Forms.Form.ControlCollection.Add(Control value) at System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add(Control c)