I am writing a "clone" function for data grid rows. When I clone an existing row the values do not appear in the cells until one of the following events:
- Manually clicks to another row in the grid
- I call the "AcceptChanges()" method.
If i call the AcceptChanges method I then lose the "Added" property of the row and it becomes "Unchanged". Below is the block of code I am using to copy the rows. When I reach the Application.DoEvents ... the cells that are marked as Readonly display their data, the cells that have user controls in them do not display until one of the events stated above.
for (int i = 0; i < gridView.SelectedRows.Count; i++)
{
object[] values = new object[gridView.ColumnCount];
for (int c = 0; c < gridView.SelectedRows[i].Cells.Count; c++)
{
if (gridView.SelectedRows[i].Cells[c].ColumnInfo.FieldName.Equals("ID"))
{ values[c] = _ID.ToString(); }
else if (gridView.SelectedRows[i].Cells[c].ColumnInfo.FieldName.Equals("description"))
{ values[c] = _Description; }
else
{ values[c] = gridView.SelectedRows[i].Cells[c].Value; }
}
gridView.Rows.Add(values);
}
Application.DoEvents();
I've tried several other methods to get the values to display but to no avail. Has anyone experienced this? and if so what solutions have you discovered?