我试图让LookUpEdit在窗体显示时显示初始值。我绑定了一个国家列表作为数据源,然后在表单加载时设置EditValue,这应该在国家LookUpEdit中显示该国家。不幸的是,它只是显示了一个空值。 LookUpEdit似乎不起作用,并允许我滚动浏览国家/地区列表并选择一个项目,并在提交表单时传回该值。DevExpress LookupEdit设置EditValue不起作用
乡村类:
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
。我确信这是一件非常简单的事情,但我没有看到它,所以任何帮助都非常感激。
感谢您的回答。有趣的是,当表单提交时,只有Country类的CountryId更新为正确的值,现在已经使初始值工作了。我希望整个对象将更新到LookUpEdit中的选定Country对象。有任何想法吗? – peacemaker
我已经更新了答案 –
感谢您的帮助,修复了它! – peacemaker