I have binded datagridview
with datatable
(Growns). My main goal is, that user can work with datagridview
(dataGridView1), filling and updating data and when button
SAVE is clicked, all data would be saved into datatable, because I need it for further work.
Everything works fine, exept saving data into datatable. What am I doing wrong?
Here is my code:
private void Form2_Load(object sender, EventArgs e) {
// TODO: This line of code loads data into the 'tekmovalecDataSet.Odrasli' table. You can move, or remove it, as needed.
this.grownsTableAdapter.Fill(this.competitorDataSet.Odrasli);
}
private void buttonSave_Click(object sender, EventArgs e) {
if (EmptySpace())
{
CompetitorDataSet.OdrasliRow newGrownsRow = competitorDataSet.Growns.NewGrownsRow();
newGrownsRow.StN = textStN.Text;
newGrownsRow.Name = textN.Text;
newGrownsRow.Surname = textSN.Text;
newGrownsRow.Club = textC.Text;
newGrownsRow.YBirth = textYB.Text;
competitorDataSet.Growns.Rows.Add(OdrasliNova);
competitorDataSet.Growns.AcceptChanges();
this.dataGridView1.DataSource = competitorDataSet.Growns;
this.Validate();
this.grownsBindingSource.EndEdit();
if (dataGridView1.BindingContext[competitorDataSet.Growns] != null)
{
dataGridView1.BindingContext[competitorDataSet.Growns].EndCurrentEdit();
}
this.grownsTableAdapter.Update(competitorDataSet.Odrasli);
this.grownsTableAdapter.Adapter.AcceptChangesDuringUpdate = true;
}
else
{
MessageBox.Show("Fill ALL data about competitor!");
}
}
P.S.: When I manually fill datatable
, on form open datagridview
is filled, so datatable
and datagridview
are connected I suppose...
P.S.2.: bool EmptySpace
works fine.