我試圖讓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