3

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

here

0

1 Answer 1

3

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.

  1. Seperate your EntityCodeFirst in another Class Project and rebuild this every you made changes.
  2. In your main project just add to Reference see image below: enter image description here
  3. Now choose the DataSource in your DataGridView with the Objectenter image description here

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; }
}
9
  • when i try this additional columns still appear. However they are different columns "Count" and "IsReadOnly"
    – Kirsten
    Commented Jan 5, 2013 at 21:02
  • strange generated columns, i think your using a third party DataGridView
    – spajce
    Commented Jan 5, 2013 at 23:21
  • I am using System.Windows.Forms.DataGridView - no 3rd party. The count and IsReadOnly columns occurred when I tried your suggestion.
    – Kirsten
    Commented Jan 6, 2013 at 4:15
  • i have put them in the question text. However I don't see how it can help since the problem is also repeatable with a different class.
    – Kirsten
    Commented Jan 6, 2013 at 8:56
  • I have the domain classes in a separate project. But the data source looks different to yours.
    – Kirsten
    Commented Jan 7, 2013 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.