Skip to main content

Grid not updating with insertion of new rows into underlying data source

Comments

3 comments

  • Dapfor Team

    Hello,

    Replace the collection of orders in the Order class with BindingList<Order>. In this case the grid can subscribe not only to the root collection but also to a collection, returned by the Order.Orders property. The grid will automatically add/remove rows when this collection is changed. You don't need fire FirePropertyChanged("Orders") if you don't instantiate a new instance of BindingList.

    Example:

     

    public class Order : INotifyPropertyChanged
    {
        private readonly IList<Order> _orders = new BindingList<Order>();
        ...
        
        [Field("Orders")]
        [HierarchicalField]
        public IList<Order> Orders
        {
            get
            {
                 return _orders;
            }
        }
    }


    Kind regards,
    Dapfor

    0
  • Dapfor Team

    Hi,

    Thanks for the quick response. I changed private IList<Order> _orders = new List<Order>();
    to private readonly IList<Order> _orders = new BindingList<Order>();


    Still no luck. When I execute

    var row = ds.OfType<Order>().Where(x => x.TicketNumber == "456").First();
    row.Orders.Add(new Order("2222", "Another Child row"));


    The gird does not show the new child row.

    Thanks,
    Chris

    0
  • Dapfor Team

    Hi Chris,

    Look at the attached demo project. Each root order contains a BindingList of suborders (of course you can have any number of hierarchies). Add/remove buttons randomly change those lists. Hope, this help you.

    Best regards,
    Dapfor




    HierarchicalFieldDemo.png
    HierarchicalFieldDemo.zip
    0

Please sign in to leave a comment.

Powered by Zendesk