私は男がいます、私はwpfコンボボックスから値を選択したいです
次のコードがあります:
private void CargarUnidades()
{
List<Unidades> unidades;
using (var sesion = NHibernateFluentConfiguracion.AbrirSesion())
{
using (var transaccion = sesion.BeginTransaction())
{
unidades = Unidades.ObtenerTodaslasUnidades();
}
}
cmbUnidad.ItemsSource = unidades;
cmbUnidad.DisplayMemberPath = "Nombre";
cmbUnidad.SelectedValuePath = "Nombre";
}
単位を充電した後
CargarUnidades(); //Charge all unidades in the combobox
Articulos c = Articulos.Obtener(id_articulo);
//Get Articulo from the database for the id
//In the last query I get the unidad same that exists in cmbUnidad
//previusly charge
//I assing the value but in the combobox doesnt appear selected,
//appear nothing
cmbUnidad.SelectedValue = c.id_unidad;
txtCodigo.Text = c.Codigo;
.
.
.
.
コンボボックスから値を選択するにはどうすればよいですか?注:私はWPFを初めて使用しますが、英語は上手ではありませんje je je
答えてくれてありがとうフィロ、私はコードを修正し、これが結果です
cmbUnidad.Items.Cast<Unidades>().FirstOrDefault(u => u.id_unidad == c.id_unidad.id_unidad);
これが最善の方法かどうかはわかりませんが、機能的には:P