am using EF Code first, and have a windows form with a bindingNavigator bound to a datasource. The data entry textboxes are also bound to the datasource
I want it to work so that
When the user opens the form
if there are no records in the data source
then the form behaves as if the user had clicked the add button.
I have tried
private void PersonForm_Load(object sender, EventArgs e)
{
if (bindingSource1.Count == 0)
{
bindingNavigator1.BindingSource.AddNew();
}
}
private void bindingSource1_AddingNew(object sender, System.ComponentModel.AddingNewEventArgs e)
{
e.NewObject = CreatePerson();
}
private Person CreatePerson()
{
var obj = new Person();
obj.RowId = Guid.NewGuid();
return obj;
}
however the record selector stays disabled and when I click save in the navigator bar the new record does not save.