【发布时间】:2017-08-29 15:19:00
【问题描述】:
我试图让 LookUpEdit 在显示表单时显示初始值。我将国家/地区列表绑定为数据源,然后在表单加载时设置 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 并将数据绑定设置为它自己的EditValue。无论我尝试什么,加载表单时 LookUpEdit 始终为空白,我需要将其设置为initialCountry。我确信这很简单,但我没有看到它,所以非常感谢任何帮助。
【问题讨论】:
标签: c# devexpress