我想将当前DataRowView更改为特定行,这样我就可以在需要的地方设置值。
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;
}
您必须循环遍历每一列,并将当前单元格的值分配给所需行的单元格。以下代码可以帮助您。
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;
}
}
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;
}
}