CurrentItemChanged event of a BindingSource is not called when changing a subitem

1

I have a class like this:

    public class Foo {

    #region Construtor
    public Foo() { }
    #endregion

    #region Propriedades

    public virtual int? Id { get; set; }
    public virtual string Description { get; set; }
    public virtual Bar Bar { get; set; }
    #endregion
}

and another:

    public class Bar  {

    #region Construtor
    public Bar() { }

    public Bar(int id, string descricao) {
        this.Id = id;
        this.Description = descricao;
    }
    #endregion

    #region Propriedades
    public virtual int? Id { get; set; }
    public virtual string Description { get; set; }

    #endregion
}

I'm doing the binding of the inputs as in the example below:

        private void Form2_Load(object sender, EventArgs e) {
        Foo foo = new Foo();
        foo.Id = 1;
        foo.Description = "Description foo";
        foo.Bar = new Bar(2, "Bar item 1");

        bindingSource.DataSource = foo;
        // Aqui o binding da descrição da classe Foo
        textBoxFoo.DataBindings.Add("TEXT", bindingSource, "Description", true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
        // Aqui o binding da descrição da classe Bar
        textBoxBar.DataBindings.Add("TEXT", bindingSource, "Bar.Description", true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);

    }

When I change the input representing the description of the Foo class the CurrentItemChanged event of the BindingSource is called correctly, however, when I change the input representing the description of the Bar class the event is not called. Could someone explain to me why this happens? How will I work with a similar model?

    
asked by anonymous 16.05.2016 / 14:24

1 answer

0

After several attempts, I have been able to solve the problem this way:

            // Aqui o binding da descrição da classe Bar
        textBoxBar.DataBindings.Add("TEXT", bindingSource, "Bar.Description", true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
        textBoxBar.DataBindings[0].BindingManagerBase.CurrentItemChanged += bindingSource_CurrentItemChanged;

I had to add the CurrentItemChanged in BindingManagerBase again ...

    
17.05.2016 / 14:46