views:

136

answers:

1

Hello community,

I have trouble editing a databound bindinglist. Let me illustrate it with the following:

Say I have the Person class:

public Class Person{
  private string m_firstname;
  private string m_lastname;
  public string FirstName{get;set;}
  public string LastName{get;set;}
  public Person{ ... }
}

I then have a containing class called Population:

public class Population{
  private BindingList<Person> m_lstPerson = new BindingList<Person>();
  private string m_countryName;
  public BindingList<Person> ListPerson{get; set;}
  public string CountryName { get; set; }
}

I then have on one form a first datagridview with DataSource = m_lstPopulation (BindingList). The binding works like a charm when working with the Population objects. When I double click, it opens up a dialog form showing the object details. One tab in the details holds a datagridview bound to that population's ListPerson.

The second datagridview displays fine. However, I cannot edit or add cells in this datagridview. None of the columns is set to read-only. In fact, both datagridview have just about the same parameters.

What am I missing? It seems that a lock has been placed on the Population object so that its inner fields cannot be edited...

Please advise. Thanks.

A: 

First verify that these grid properties are set:

ReadOnly = false; AllowUserToAddRow = true; EditMode = ;

If that doesn't work then you may be getting stuck in edit mode... It sounds like you have some custom behavior on your grid ("When I double click, it opens up a dialog form showing the object details.")...

For this try calling DataGridView.CancelEdit() after your dialog closes to end the edit session on the clicked row. This will restore the "new row" row to the grid. It disappears when you begin editing another row, which, depending on the EditMode setting may begin when you click on (enter) another row.

Preston