DataGridView, preventing CancelNew

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

Hi,

I have a DataGridView bound to a BindingList. When the user clicks on the
"new row" row at the bottom of the grid, a new row gets added with all the
right defaults, etc. The problem is that, unless they edit this row, it
disappears the moment they leave it. I would like for the new row to stay
put even if they do not edit it (the defaults are most often good and do not
need editing).

I have tried to call EndNew from AddNewCore, but that did not help.

Any help on this would be much appreciated.

Thanks,
Jim


Ps. Here is a simple test app to demonstrate:

namespace TestApp
{
public partial class Form1 : Form
{
PersonList _persons = new PersonList();
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = _persons;
}
}

public class PersonList : BindingList<Person>
{
public PersonList ()
: base ()
{
AllowNew = true;
}

protected override object AddNewCore()
{
Person person = new Person("<Type name here>");
Add(person);
base.EndNew(this.IndexOf(person));
return person;
}
}

public class Person
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}

public Person(string name)
{
_name = name;
}
}
}
 
Back
Top