I'm trying to insert a default value using a datagrid whit binding navigator.
If I insert a new record from cliccking the asterisk in the left/bottom of the form "DefaultValuesNeeded" works fine .
If I insert a new record cliccking the plus, using this code, it's insert a good row and a null row using the trigger in the "bindingNavigatorAddNewItem_Click".
Where is the problem ?
Thanks a lot.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GRIDDEFAULT
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void rUBRICABindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.rUBRICABindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.dMCODataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: questa riga di codice carica i dati nella tabella 'dMCODataSet.RUBRICA'. È possibile spostarla o rimuoverla se necessario.
this.rUBRICATableAdapter.Fill(this.dMCODataSet.RUBRICA);
}
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{
// BindingNavigator button's AddNewItem automatic tie-in to bindingSource's AddNew() is removed
// This sets the current cell to the NewRow's cell to trigger DefaultValuesNeeded event
rUBRICADataGridView.CurrentCell = rUBRICADataGridView.Rows[rUBRICADataGridView.NewRowIndex].Cells[0];
}
private void rUBRICADataGridView_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
// Gets called when datagridview's */NewRow is entered.
e.Row.Cells[0].Value = 1;
e.Row.Cells[1].Value = "nome";
e.Row.Cells[2].Value = "cognome";
}
}
}