将当前 DataRowView 更改为特定的 DataRowView
Change current DataRowView to a specific DataRowView
我想将当前的 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;
}
}
我想将当前的 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;
}
}