gpt4 book ai didi

c# - XtraGrid 单元格值中的 LookupEdit 变为空白

转载 作者:太空狗 更新时间:2023-10-30 00:27:12 27 4
gpt4 key购买 nike

这是我的:

public class ViewModel
{
public BindingList<Row> Rows { get; set; }
public BindingList<MyElement> Selectables { get; set; }
}

public class Row
{
public MyElement Selected { get; set; }
}

public class MyElement
{
public string Value { get; set; }
public string Friendly { get; set; }
}

这就是我想要的:XtraGrid 的列在每个单元格中都有一个组合框编辑器。不同行的下拉选项值不同。具体来说,可用选项是 ViewModel.Selectables 的子集,该子集在运行时由业务规则定义。

这就是我尝试实现这一目标的方式:

我创建了三个 BindingSources

  1. viewModelBindingSource:使用 DataSource = ViewModel

  2. rowsBindingSource:DataSource = viewModelBindingSource AND DataMember = Rows

  3. selectablesBindingSourceDataSource = viewModelBindingSource AND DataMember = Selectables

我将网格的 DataSource 设置为 rowsBindingSource。我为网格中的 LookupEdit 创建了一个就地编辑器存储库。我将 repositoryItemLookUpEditDataSource 设置为 selecteablesBindingSource我将 repositoryItemLookUpEdit 设置为列的 ColumnEdit

我连接到 gridViews ShownEditor 事件:

this.gridView1.ShownEditor += gridView1_ShownEditor;

gridView1_ShownEditor(object sender, EventArgs e) 方法中,我可以引用 View ,这样我就可以做这样的事情:

GridView view = sender as GridView;
var newSelectables = new BindingList<MyElement>();
// businesslogic to populate newSelectables ...
var bs = new BindingSource(newSelectables, "");
edit = (LookUpEdit)view.ActiveEditor;
edit.Properties.DataSource = bs;

这在一定程度上起作用,我在单击的组合框中获得了新选项,并且选择该选项将值设置为绑定(bind)对象,即 Row.Selected .

现在我的问题是,当单元格失去焦点时,单元格内容变为空白

这似乎是由于我用新的创建了一个新的 BindingSource 造成的,因为如果我省略 DataSource 的这个更改,那么 中的值ViewModel.Selectables 被改用,它按预期工作。

那么,有谁知道为什么在这种情况下单元格失去焦点后显示在单元格中的文本变成空白??

最佳答案

几天前我遇到了同样的问题,但我没有找到任何解决方案。我从中了解到,您绑定(bind)到包含 ComboEdit 或 LookupEdit 的网格列的值必须与 ComboEdit/LookUpEdit 集合的 Vlaue 成员值相匹配。

如果找到匹配的值,它将在单元格中显示显示成员值,否则单元格值将为空。

这是我从我的工作经验中得到的。

关于c# - XtraGrid 单元格值中的 LookupEdit 变为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7547384/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com