SyncfusionExamples / Filter-xamarin.forms-listview-based-on-swiped-items-in-another-listview

Sample showcases how to filter xamarin.forms listview based on swiped items in another listview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filter listview items based on another listview selection

To filter the listview items based on the item selection in another listview, use the SfListView.DataSource.Filter property.

private void ItemTapped(Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
    tappedPinedInfo = e.ItemData as PinnedInfo;
    if (tappedPinedInfo.IsFavorite)
    {
        secondLV.DataSource.Filter = FilterDepartures;
        tappedPinedInfo.IsFavorite = false;
    }
    else
    {
        secondLV.DataSource.Filter = null;
        tappedPinedInfo.IsFavorite = true;
    }
    secondLV.DataSource.RefreshFilter();
}

private bool FilterDepartures(object obj)
{
    var departureInfo = obj as DepartureInfo;
    if (tappedPinedInfo == null)
        return true;

    if (departureInfo.Name.ToLower().Contains(tappedPinedInfo.Name.ToLower())
            || departureInfo.RouteName.ToLower().Contains(tappedPinedInfo.RouteName.ToLower()))
        return true;
    else
        return false;
}

Swipe and move an item to another listview on siwpe item tapped action

By using swipe view action, you can move an item from one listview to another listview.

private void FavoriteTapped(object obj)
{
    var departureInfo = obj as DepartureInfo;
    var pinnedInfo = FirstLVCollection.Any(o => o.Name == departureInfo.Name) ? FirstLVCollection.First(o => o.Name == departureInfo.Name) : null;
    if (pinnedInfo == null)
    {
        FirstLVCollection.Add(new PinnedInfo() { Name = departureInfo.Name, RouteName = departureInfo.Name, Icon = departureInfo.Icon, IsFavorite = true });
    }
}

To know more about ListView, please refer our documentation here

About

Sample showcases how to filter xamarin.forms listview based on swiped items in another listview


Languages

Language:C# 100.0%