tags:

views:

11

answers:

0

I have a DataGridView connected to a SortableBindingList.

        db = new eScanEntities();
        bs = new BindingSource();
        List<Doctor> lDoctor = db.Doctor.OrderBy(o => o.DoctorNo).ToList();
        bs.DataSource = new Classes.SortableBindingList<Doctor>(lDoctor);
        dataGridView1.DataSource = bs;

I can edit a record in a grid and save it without problems. But, when I add a new record, it doesn't get saved.

    private void btnAdd_Click(object sender, EventArgs e)
    {
        bs.AddNew(); 
        dataGridView1.CurrentCell = dataGridView1["DoctorNo", dataGridView1.CurrentCell.RowIndex];
        this.ActiveControl = dataGridView1;
    }

    private void btnClose_Click(object sender, EventArgs e)
    {
        int rowsAffected = db.SaveChanges(true);
        MessageBox.Show(rowsAffected.ToString() + " changes made."); 
        this.Close();
    }

rowsAffected is 1 if I edited 1 record, but is 0 if I added one record.

Why? What am I missing here? Thanks.