- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图让 LookUpEdit 在显示表单时显示初始值。我将国家列表绑定(bind)为数据源,然后在加载表单时设置 EditValue,这应该将国家显示为 LookUpEdit 中的选定项。不幸的是,它只显示一个空值。 LookUpEdit 似乎可以正常工作,它允许我滚动浏览国家/地区列表并选择一个项目,当我提交表单时该值会传回。
国家类:
public class Country
{
public Country();
public int CountryId {get; set;}
public string CountryName {get; set;}
public string IsoCode {get; set; }
}
包含 LookUpEdit 的表单背后的代码:
this.country.Properties.DataSource = this.Countries;
this.country.Properties.DisplayMember = "CountryName";
this.country.Properties.ValueMember = "CountryId";
this.country.EditValue = initialCountry;
this.country.DataBindings.Add("EditValue", viewModel.Address, "AddressCountry", false, DataSourceUpdateMode.OnPropertyChanged);
在这个例子中 this.Countries
人口稠密 List<Country>
和 initialCountry
设置为 Country
的一个实例和 viewModel.Address
包含属性 Country AddressCountry
.
我都试过设置 EditValue
仅直接并将数据绑定(bind)设置为它自己的 EditValue。无论我尝试什么,加载表单时 LookUpEdit 始终为空白,我需要将其设置为 initialCountry
.我确信它非常简单,但我没有看到它,所以非常感谢任何帮助。
最佳答案
除了Marko的回答:
有一个特殊模式data binding to the entire business objects在查找中:
this.country.Properties.DataSource = this.Countries;
this.country.Properties.DisplayMember = "CountryName";
this.country.Properties.KeyMember = "CountryId";
this.country.EditValue = initialCountry;
此模式允许查找机制通过关键字段(“CountryId”)分配给 RepositoryItemLookUpEditBase.KeyMember属性(property)。
以下是此模式的一些额外好处:
您可以使用多个键字段(“复合键”功能);
//用';'分隔的字段名称字符
this.city.Properties.KeyMember = "CountryId;RegionId;CityName";
您可以匹配从单独的数据上下文加载的业务对象,并利用延迟加载方法的所有优点:
//CountryId 值足够匹配
//加载时可以跳过所有其他字段(例如CountryName)
this.country.EditValue = new Country() { CountryId = 5 }
关于c# - DevExpress LookupEdit 设置 EditValue 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45942804/
我试图让 LookUpEdit 在显示表单时显示初始值。我将国家列表绑定(bind)为数据源,然后在加载表单时设置 EditValue,这应该将国家显示为 LookUpEdit 中的选定项。不幸的是,
我正在调整 WinForms 应用程序。此应用程序有一个包含 PropertyGrid 的 Form。一个对象被分配给 SelectedObject 属性,以便属性网格显示该对象的属性。 分配的对象类
我是一名优秀的程序员,十分优秀!