DataGridView, preventing CancelNew

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;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top