0

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;
}
Jimi
  • 29,621
  • 8
  • 43
  • 61
MaxB
  • 260
  • 2
  • 13

2 Answers2

1

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;
        }
    }
0
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;
  }
}
  • Welcome to the site. Take into account that, while this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Ángela Mar 16 '22 at 09:24