CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    4

    Entity Framework Lists, Static Resources and Filtering a BindingListCollectionView

    Hi

    my view model has a dependency property ActiveWellLocation which is an ADO.Net Entity framework object, wellLocation, which is associated with wellSample which has an associated list wellAliquot, so:

    ActiveWellLocation.wellSample.wellAliquot - is a collection and I can successfully bind to my datagrid

    <dgataGrid x:Name="additivesDataGrid" HorizontalAlignment="Center" Margin="2" Width="302" Height="150"
    AutoGenerateColumns="False"

    ItemsSource="{Binding ActiveWellLocation.wellSample.wellAliquot}"
    ....
    </dgataGrid>

    I need to filter my wellAliquot collection and thus investigated indirecting thru a static resource. The following snippets of the CollectionViewSource and associated binding on the datagrid also bind ok:


    <CollectionViewSource Source="{Binding ActiveWellLocation.wellSample.wellAliquot}" x:Key="WellAliquotsWithAdditives" />

    with

    <dgataGrid x:Name="additivesDataGrid" HorizontalAlignment="Center" Margin="2" Width="302" Height="150"
    AutoGenerateColumns="False"

    ItemsSource="{Binding Source={StaticResource WellAliquotsWithAdditives}}"
    ....
    </dgataGrid

    I was intending to filter the CollectionViewSource (of type BindingListCollectionView) as my dp ActiveWellLocation updates. In short my view model fires an event to which the user control listens. In the event handler I have tried a couple of different ways to get hold of the resource but they fail, one example was

    public void PropertyChangedListener(object sender, PropertyChangedEventArgs e)
    {
    string name = e.PropertyName;
    switch (name)
    {
    case Avacta.Optim.Client.Models.PlateSampleViewModel.PLATE:
    //object src = FindResource("WellAliquotsWithAdditives");
    object srcWellAliquotsWithAdditives = this.Resources["WellAliquotsWithAdditives"];
    //ICollectionView iblcv = CollectionViewSource.GetDefaultView(srcWellAliquotsWithAdditives);
    BindingListCollectionView blcv = (BindingListCollectionView)CollectionViewSource.GetDefaultView(srcWellAliquotsWithAdditives);
    blcv.CustomFilter = "additive <> null";
    break;
    default:
    break;
    }
    }

    To date I have been unable to get the resource and therefore the view. (also I expect the filter 'code' is not suitable, any clues to the correct filter appreciated)

    Any ideas as to the 'correct' approach?

    Cheers

    AndyF.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Entity Framework Lists, Static Resources and Filtering a BindingListCollectionVie

    You can get the ICollectionView pointer from your DataGrid - no need to use FindResource.

    Code:
     
    ICollectionView dataView =
          CollectionViewSource.GetDefaultView(additivesDataGrid.ItemsSource);

  3. #3
    Join Date
    Jul 2009
    Posts
    4

    Re: Entity Framework Lists, Static Resources and Filtering a BindingListCollectionVie

    Thanks Arjay

    tried the code and it worked 2nd time around, 1st time null! Unfortunately the underlying data binding is not completed when the event (driven by a change in the main dependency property) fires and is caught by the control (or so it seems..)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured