tags:

views:

9

answers:

1

I have a DataGridView that I load in unbound mode. When first loaded the edit is set to I have a button where a user can "Add New"

Pressing this it will add a new row then I do

dgv.Rows[dgv.Rows.Count - 1].Selected = true;"
dgv.EditMode = DataGridViewEditMode.EditOnEnter;

However the caret focus is elsewhere.

I also would like the first cell to get the focus.

Any ideas?

A: 
  1. Use a BindingSource for your grid (lots of reasons)
    dgv.DataSource = bindingSourceCustomers;
  2. bindingSourceCustomers.DataSource is unassigned (unbound)
  3. Use bindingSourceCustomers.AddNew();
    Does exactly what you want.

More info here http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.addnew.aspx

Peter Gfader