我在DataGrid中有n行的数据,DataGrid是ReadOnly。现在我的目标是当我选择任何行或行时,然后按下EDIT按钮,那么所有选定的行只会变成ReadOnly = false。以便我想编辑选定行中的一些数据。在此之后,当我按下更新按钮时,只有选定的行使用EntityFramework进行更新。 我在WinForm DataGridView中完成了这个任务。现在我想在WPF DataGrid中做同样的事情。等价的WinForm DataGridView代码WPF DataGrid
private void editCust_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
foreach (DataGridViewRow item in dataGridView1.SelectedRows)
{
for (int i = 1; i <= 3; i++)
{
item.Cells[i].ReadOnly = false;
}
}
}
else
{
MessageBox.Show("No Row Is Selected To Edit.");
}
}
private void updateCust_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
foreach (DataGridViewRow item in dataGridView1.SelectedRows)
{
cutable.Customer_Name = (string)item.Cells[1].Value;
cutable.Counter = int.Parse(Convert.ToString(item.Cells[2].Value));
cutable.Buying_Cost = float.Parse(Convert.ToString(item.Cells[3].Value));
for (int i = 1; i <= 3; i++)
{
item.Cells[i].ReadOnly = true;
}
}
db.SaveChanges();
MessageBox.Show("Record Is Update.");
}
else
{
MessageBox.Show("No Row Is Selected To Update.");
}
}
你能解释什么是逻辑或什么是你的代码背后的动机,以便我们可以给你一个Datagrid的解决方案 –
Thanks @Learning for the reply。 在WPF中,我在DataGrid中有n行的数据,而DataGrid是ReadOnly。现在我的目标是当我选择任何行或行时,然后按下EDIT按钮,那么所有选定的行只会变成ReadOnly = false。以便我想编辑选定行中的一些数据。在此之后,当我按下更新按钮,那么只有选定的行使用EntityFramework –
更新域名模型/表名称是什么?在哪些数据将被更新 –