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
45
Tracking current child record of a bound collectionview
posted

We're currently following MVVM, and need to track the current child record of a parent record. The datagrid is bound to a collectionview of parent items.

 

So:

ParentViewModel

{

   CollectionView Parents {get; set;}

}

class Parent

{

  ObservableCollection Children {get; set;}

}

 

Now, the datagrid properly displays our parent records, and you can expand to see the children child records. And, the parent collectionview properly allows us to track the current record, to change current record, add, insert, etc etc.

My question is: We need to iterate through the children of a parent in the viewmodel, and have the grid select the current child record we are processing.

I tried changing Children to a CollectionView from an ObservableCollection, without much luck. Another approach would be to have our view (not the viewmodel) respond to events from the ViewModel, so that when the current item is changed (be it a Parent or Child), an event would be raised with parent/child information, indexes, etc and have the view select the appropriate record).

Any suggestions?

 

 

Parents
  • 45
    posted

    Just a quick note on this: I got the datagrid bound to a collectionview of parent items, with a child collectionview of children items.

    Changing the Parent collectionview current item properly updated the grid to the current parent record.

    Doing the same for the child collectionview (collectionview.MoveCurrentToLast) for example, did not update the data grid automatically.

    So, if the datagrid is bound to a collection with child records, and you wish to update the datagrid to show the current child item being processed, how would you go about that?

Reply Children