'Change current DataRowView to a specific DataRowView

I would like to change the current DataRowView to a specific line, so I can set the value where I want to.

public void SetTimeFromTimer(DateTime date, string timeFromTimer)
{
     monthCalendar1.SetDate(date);
     dataGridView1.ClearSelection();
     dataGridView1.Rows[1].Selected = true;
     DataRowView rowView = (DataRowView)BindingContext[repTimeTable].Current;
     rowView["zr"] = timeFromTimer;
}


Solution 1:[1]

public void SetTimeFromTimer(DateTime date, string timeFromTimer)
{
  monthCalendar1.SetDate(date);
  dataGridView1.ClearSelection();
  int rowIndex = repTimeTable.Rows.IndexOf(repTimeTable.Select($"zraufnr = '{GetProjectNumber}' AND zrpnr = '{GetPersonalNumber}'")[0]);
  if (!string.IsNullOrEmpty(rowIndex.ToString()))
  {
    dataGridView1.CurrentCell = dataGridView1.Rows[rowIndex].Cells[ColumnZrZeit.Index];
    DataRowView rowView = (DataRowView) BindingContext[repTimeTable].Current;
    rowView["zr"] = timeFromTimer;
  }
}

Solution 2:[2]

You would have to loop through each column and assign the value of the current cell to the desired row's cell. The following code can help you.

public void ChangeRowValues(int parentRow, int rowToBeChanged)
    {
        for (int i = 0; i < dataGridView.Columns.Count; i++)
        {
            dataGridView.Rows[rowToBeChanged].Cells[i].Value = 
            dataGridView.Rows[parentRow].Cells[i].Value;
        }
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JohnnyDorcy
Solution 2 Nikunj Gaur