Skip to content

Data Grid View Add New Row #2842

Description

@itg-assistant

Ewan Walker asked 2020-09-11 08:35:42 UTC

This code used to work prior to version 2.2.

I found when adding a new row directly to a DGV it was not adding it to the bound data table so I had to programatically add the data to the table using the code below

if (Adding)
{
//Underlying datable does not contain new row so we have to add it
DataRow NR = dtTest.NewRow();
for (int j = 0; j < dgvTest.Columns.Count; j++)
{
NR[j] = dgvTest[j, e.RowIndex].Value;
}
dtTest.Rows.Add(NR); //Adds two rows to data table why?
dtTest.Rows[e.RowIndex +1].AcceptChanges();
dtTest.RejectChanges(); //removes duplicate - Fails here now - workaround to remove extra row if commented out two rows added
dtTest.Rows[bsTest.Position].SetAdded();
dm.Update(dtTest, "updEmps", "", 46);
}

Thanks for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions