Question

so I'm slowly trying to learn the ways of databinding so I can apply it to work.....right now I have a simple class binded to a listview

now let's say I wanted to filter the results to say show only a certain league..how can I do that through databinding if say a button is clicked?

at the moment if i had to that... i would have the button clear the listview.. and cycle through the observerablecollection and if a league == to whatever i want.. then I would manually add it to the listview.

i feel like there's probably something easier with this whole databinding thing and i'm probably missing something... is there a more elegant way of performing such a task and controlling what's displayed in a listview?

what I currently have:

    public ObservableCollection<Templates.MLBData> _MLBCollection = new ObservableCollection<Templates.MLBData>();

    public class MLBData
    {
        public string league { get; set; }
        public string category { get; set; }
    }

        <ListView Name="myListView" MouseDoubleClick="myListView_MouseDoubleClick_1"
                  ItemsSource="{Binding ElementName=This, Path=MLBCollection}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="H1" Width="100" DisplayMemberBinding="{Binding league}"/>
                    <GridViewColumn Header="H2" Width="100" DisplayMemberBinding="{Binding category}"/>
                </GridView>
            </ListView.View>
        </ListView>
Was it helpful?

Solution

You could use a ICollectionView .. Here is a good example... http://jacobmsaylor.com/?p=1270

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top