0
我已經創建了一個自定義只讀組合框,大部分的作品。但是,當我從外部源下載數據並設置數據綁定時,會出現一些非常奇怪的行爲。請看下面的代碼:數據綁定問題與自定義組合框
cboGender.DataSource = Animal.SpecificGenders;
cboGender.DataBindings.Clear();
cboGender.DataBindings.Add("text", animal, "Gender");
((ReadOnlyComboBox)cboGender).Readonly = true;
當上線命中,它調用此屬性:
public bool Readonly
{
get
{
return readOnly;
}
set
{
textBox.Text = this.Text;
ShowControl();
readOnly = value;
}
}
現在,我的問題是,當我只讀設置爲false,這工作正常。上面的setter中的'this.Text'顯示了綁定的值。但是,當我將Reaonly設置爲true時,'this.Text'顯示一個空字符串。這是我唯一的區別。 this.Text指的是標準的Combobox Text屬性。
有沒有人有任何想法?