【发布时间】:2020-08-21 16:46:20
【问题描述】:
我正在做一个项目,我的基础是一个在 Windows 窗体中存在的项目,问题是在 WPF 中没有 DataGridView,只有 DataGrid,当我想选择一行时会产生问题修改它
private void btnEditar_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
Editar = true;
txtNombre.Text = dataGridView1.CurrentRow.Cells["Nombre"].Value.ToString();
txtMarca.Text = dataGridView1.CurrentRow.Cells["Marca"].Value.ToString();
txtDesc.Text = dataGridView1.CurrentRow.Cells["Descripcion"].Value.ToString();
txtPrecio.Text = dataGridView1.CurrentRow.Cells["Precio"].Value.ToString();
txtStock.Text = dataGridView1.CurrentRow.Cells["Stock"].Value.ToString();
idProducto = dataGridView1.CurrentRow.Cells["Id"].Value.ToString();
}
else
MessageBox.Show("seleccione una fila por favor");
}
【问题讨论】:
-
理想的方法是使用 MVVM 模式(为数据类型创建一个类,然后将其设为视图的 dataContext,然后在 xaml 中绑定属性)。为您提供真正等效的 wpf 代码将是一个糟糕的建议。
标签: c# wpf visual-studio