Data binding for TextBox

后端 未结 4 1809
难免孤独
难免孤独 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:27

    You need a bindingsource object to act as an intermediary and assist in the binding. Then instead of updating the user interface, update the underlining model.

    var model = (Fruit) bindingSource1.DataSource;
    
    model.FruitType = "oranges";
    
    bindingSource.ResetBindings();
    

    Read up on BindingSource and simple data binding for Windows Forms.

提交回复
热议问题