Need help filtering an AlphaKEyGroup

36 views Asked by At

I´ve been searching the site and internet trying to find a solution but I couldn´t find it.

I have ordered my items using the AlphaKeyGroup example provided by Microsoft. However, the users will have a search box at the top, also, to filter this list and I can´t realize on how to do this filtering.

The MS says

private void getListItems()
    {
        var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(
Database_Controller.getStoreValues(), // basic list of items
(Stores s) => { return s.Name; },  // the property to sort
 true);                           // order the items
        // returns type List<AlphaKeyGroup<SampleItem>>

        ListViewCollectionSource.Source = alphaKeyGroup;
    }

So I have try these two ways

var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(Database_Controller.getStoreValues(), (Stores s) => s.Name, true).Where(s => Name.Contains(searchKeyword.Text));


var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(Database_Controller.getStoreValues(), (Stores s) => { return s.Name.Where(s.Name.Contains(searchKeyword.Text)) ; },true);

The first one brings nothing to the ListView, and the second does not compile.

What am I doing wrong?

1

There are 1 answers

0
Gustavo On

I have found a workaround about this and IT´S WORKING!!!

(anyway, you guys tell me if this is the best way to do it)

private void storeTesting(object sender, TextChangedEventArgs e)
    {
        List<Stores> storeTest = new List<Stores>();
        try
        {
            if (searchKeyword.Text != "")
            {
                Debug.WriteLine(searchKeyword.Text);

                foreach (Stores storeToShow in storesSource)
                {
                    if (storeToShow.Name.Contains(searchKeyword.Text))
                    {
                        storeTest.Add(storeToShow);
                    }
                }
            }
            else
            {
                Debug.WriteLine(searchKeyword.Text + "the text is null");
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.ToString());
        }

        var alphaKeyGroup = AlphaKeyGroup<Stores>.CreateGroups(storeTest, (Stores s) => { return s.Name; }, true);
        ListViewCollectionSource.Source = alphaKeyGroup;
    }