C # WinForms BindingList & DataGridView - disallowing EDIT prevents new row from being created? How can I answer this?

As far as my use of a DataGridView with a BindingList, I should have disabled editing of the current rows, but allowed new rows to be added. The problem is that when I disallow changes, it does not seem to allow a new row element to be added, as with a table in a cell for that new row, it does not seem to allow editing.

Know how to get around this? A section of my code below:

   BindingSource bs = new BindingSource();
   bList = new BindingList<Customer>();
   bList.AllowNew = true;
   bList.AllowEdit = false;

   // Fill bList with Customers
   bList.Add(new Customer("Ted"));
   bList.Add(new Customer("Greg"));
   bList.Add(new Customer("John"));

   bs.DataSource = bList;
   dataGridView1.DataSource = bs;

      

thank

+2


source to share


1 answer


Rather than wrestling with the source, perhaps ask for DataGridView

judging:

dataGridView1.DataSource = bs;
dataGridView1.ReadOnly = true;
dataGridView1.CurrentCellChanged += delegate 
{
    DataGridViewRow row = dataGridView1.CurrentRow;
    bool readOnly = row == null ||
        row.Index != dataGridView1.NewRowIndex;
    dataGridView1.ReadOnly = readOnly;
};

      



(and don't install AllowEdit

in the list)

+4


source







All Articles