Data binding for TextBox

后端 未结 4 1749
难免孤独
难免孤独 2020-11-28 09:04

I have a basic property that stores an object of type Fruit:

Fruit food;
public Fruit Food
{
    get {return this.food;}
    set
    {
        this.food= val         


        
4条回答
  •  醉梦人生
    2020-11-28 09:32

    I Recommend you implement INotifyPropertyChanged and change your databinding code to this:

    this.textBox.DataBindings.Add("Text",
                                    this.Food,
                                    "Name",
                                    false,
                                    DataSourceUpdateMode.OnPropertyChanged);
    

    That'll fix it.

    Note that the default DataSourceUpdateMode is OnValidation, so if you don't specify OnPropertyChanged, the model object won't be updated until after your validations have occurred.

提交回复
热议问题