I am trying to write a header-detail form. in VS2010 C# Winforms.
The form binds to an Entity Framework class with an property called Attendees
using a BindingSource control called bindingSource1.
The grid is bound to another BindingSource control with datasource = bindingSource1 and DataMember = Attendees
I am using code first EF. The entity class is
public class ContactEvent
{
public int Id { get; set; }
public string Title { get; set; }
private readonly BindingList<ContactEventAttendee> _attendees = new BindingList<ContactEventAttendee>();
public virtual BindingList<ContactEventAttendee> Attendees
{
get { return _attendees; }
}
}
I set the columns using the designer, deleting all the columns I don't want. As soon as I save the form and re-open it the columns I dont want are back
I have looked here and tried the technique - but it doesn't help. Anyway - my problem shows at design time.
The problem only occurs if I delete all the bound columns. Since all my columns are unbound this is what I want.
The ContactEventAttendee class is as follows;
public class ContactEventAttendee : ILoggedEntity
{
public int Id { get; set; }
public Guid RowId { get; set; }
[ConcurrencyCheck]
public int RowVersionId { get; set; }
public int SourceSiteNumber { get; set; }
public virtual ContactEvent ContactEvent { get; set; }
public virtual Person Person { get; set; }
}
I get the same problem with another related class as well. The problem disappears if I delete the bindingNavigator from the form
The data source is

give it a try.
public class ContactEvent
{
public int Id { get; set; }
public string Title { get; set; }
public virtual ICollection<ContactEventAttendee> ContactEventAttendees {get; set;}
}
EDIT
okay, i am having with exact problem when i tried to create a project and set the DataSource with your Class to DataGridView and this another strange bug? well, we really don't know but here my solution.
EntityCodeFirst in another Class Project and rebuild this every you made changes.Reference see image below: 
DataGridView with the Object
Now, try to delete all the columns and rebuild it again.
EDIT: Reference of my sample
public class ContactEvent
{
public int Id { get; set; }
public string Title { get; set; }
public ICollection<ContactEventAttendee> _attendees { get; set;}
}
public class ContactEventAttendee
{
public int Id { get; set; }
public Guid RowId { get; set; }
public int RowVersionId { get; set; }
public int SourceSiteNumber { get; set; }
public virtual ContactEvent ContactEvent { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With