Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
680
force grid rebind to objects
posted

I have a grid bound to a collection of objects each object has a collection of child objects and they all display nicely e.g.

 

object 1

child 1

child 2

object 2

child 1

 

Now in code I add a child to object 2 e.g. MyObject2.Add(child) i then can view the collection at runtime e.g.

((List<MyObject>)myGrid.DataSource)

And this shows that the child has been added succesfully, however if i call myGrid.DataBind() the new child does not appear in the child band in the grid.

How do I get it to appear automatically ??

If I do the following I lose my current layout and positioning but the child is there:

var data = ((List<MyObject>)myGrid.DataSource);

myGrid.DataSource = null;

myGrid.DataSource = data;

 

 

 

 

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi,

    List<T> is not a very good data source to use for Binding. It doesn't send notification when a new row is added or an existing row is modified.

    I recommend using BindingList<T> instead. That will make things better - the BindingList will notify bound controls when new rows are added.

    In order to get notification when a field value is changed, you will need to implement INotifyPropertyChanged on MyObject.

    Or... if you don't want to (or can't) change your data source, you can refresh the grid manually by calling grid.Rows.Refresh(ReloadData).

Children