Home > database >  How to return processed collection on ListView xamarin
How to return processed collection on ListView xamarin

Time:10-03

I want to check with if statement and want to display only these values which are checked on the listview.

`  public void MarkerPressed2()
        {
            MessagingCenter.Subscribe<object, IEnumerable<AlertLevelOnClick>>(this, "PinInfo", (sender, arg) =>
            {
                lstLevel2.ItemsSource = arg;

                var listAlert = new List<AlertLevelOnClick>();

                foreach (var item in arg)
                {
                    
                    var currentData = new AlertLevelOnClick() {
                        dateForecastOnClick = item.dateForecastOnClick,
                        levelForecastOnClick = item.levelForecastOnClick

                    };

                    listAlert.Add(currentData);

                   

                    if (item.levelForecastOnClick == 1)
                    {
                        //how to return every rows on arg or on listview lstLevel2.ItemsSource = arg; with checked
                        //item.levelForecastOnClick and item.dateForecastOnClick on the listView like
                        var test = 5;

                    }
                    else if (item.levelForecastOnClick == 2)
                    {
                         //how to return every rows on arg or on listview lstLevel2.ItemsSource = arg; with checked
                        //item.levelForecastOnClick and item.dateForecastOnClick on the listView like 
                    }
                }
            });

           
        }

With this code: lstLevel2.ItemsSource = arg; I fill the listview but I want to check first if the levelForecastOnClick == 1 and want to display only values which is 1 and his date dateForecastOnClick

How it's possible to return check arg collection on lstLevel2.ItemsSource ?

CodePudding user response:

// create an empty list
var listAlert = new List<AlertLevelOnClick>();

foreach (var item in arg)
{
   // if an item meets whatever conditions you want to test for
   if (item.levelForecastOnClick == 1 && ...)
   {
      // add it to the list
      listAlert.Add(item);
   }
}

// assign your filtered list to the ListView ItemsSource             
lstLevel2.ItemsSource = listAlert;
  • Related