从代码生成的 WPF DataGridComboBoxColumn
我正在从与数据表关联的可编辑数据网格视图中包含的代码生成组合格式的列。
当我将自己置于单元格中时,会出现带有值的组合,但我无法在单元格中显示 SelectedValue。事实上,在初始数据加载中,该单元格不再显示数据列表的值(我收到数据表中的值 0,1 或 2),并且我想不知何故我不知道如何创建必要的绑定。
protected override void OnAutoGeneratingColumn(DataGridAutoGeneratingColumnEventArgs e)
{
if ( e.PropertyName == "combocolumn") {
var cb = new DataGridComboBoxColumn();
cb.Header = "ColumnCombo";
cb.Visibility = Visibility.Visible;
cb.IsReadOnly = false;
cb.DisplayMemberPath = "Descripcion";
cb.SelectedValuePath = "Codigo";
cb.ItemsSource = Datos;
e.Column = cb;
}
base.OnAutoGeneratingColumn(e);
}
// ===> datos ...
public class DatosCombo
{
public int Codigo { get; set; }
public string Descripcion { get; set; }
}
private List<DatosCombo> Datos= new List<DatosCombo>()
{
new DatosCombo() { Codigo = 0,Descripcion="Dato1"},
new DatosCombo() { Codigo = 1,Descripcion="Dato2"},
new DatosCombo() { Codigo = 2,Descripcion="Dato3"}
};
I am generating a column in combo format from code that is included in an editable datagridview associated with a DataTable.
When I place myself in the cell, the combo with the values appears, but I can't get the SelectedValue to be displayed in the cell. In fact, in the initial data load, that cell no longer shows the value of the data list (I receive the values, 0,1, or 2 in the data table), and I suppose that somehow I have not known how to create the binding necessary.
protected override void OnAutoGeneratingColumn(DataGridAutoGeneratingColumnEventArgs e)
{
if ( e.PropertyName == "combocolumn") {
var cb = new DataGridComboBoxColumn();
cb.Header = "ColumnCombo";
cb.Visibility = Visibility.Visible;
cb.IsReadOnly = false;
cb.DisplayMemberPath = "Descripcion";
cb.SelectedValuePath = "Codigo";
cb.ItemsSource = Datos;
e.Column = cb;
}
base.OnAutoGeneratingColumn(e);
}
// ===> datos ...
public class DatosCombo
{
public int Codigo { get; set; }
public string Descripcion { get; set; }
}
private List<DatosCombo> Datos= new List<DatosCombo>()
{
new DatosCombo() { Codigo = 0,Descripcion="Dato1"},
new DatosCombo() { Codigo = 1,Descripcion="Dato2"},
new DatosCombo() { Codigo = 2,Descripcion="Dato3"}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它对更多人有用,我已经通过添加解决了这个问题:
In case it is useful for more people, I already solved the problem by adding :