How about I have a problem with a ListView I am using C# with Xamarin Forms and I don't know how to add values to the ListView without repeating them, I hope you can help me greetings.
I haven't tried anything yet
InventoryPerRowModel.Add(new InventoryPerRow { IntRow = Convert.ToInt32(Row.Text), IntPlants = Convert.ToInt32(TotalPlants.Text), IntPlantsUnusable = Convert.ToInt32(PlantsUnusable.Text) });
var InventoryPorSurcoModelOrdenado = InventoryPorSurcoModel.OrderBy(x => x.IntSurco).ToList(); MyListView.ItemsSource = InventoryByPathSortedModel;
CodePudding user response:
if your data looks like this
ObservableCollection<int> myData = new ObservableCollection<int>();
myData.Add(1);
...
myData.Add(10);
myListView.ItemsSource = myData;
then when you want to add a new value
private void AddToList(int i)
{
if (myData.Contains(i))
{
// already in the list, throw an error
}
else
{
myData.Add(i);
}
}
CodePudding user response:
Best way - use ObservableCollection (Jasons answer).
Is not well, but working:
var InventoryPorSurcoModelOrdenado = InventoryPorSurcoModel
.OrderBy(x => x.IntSurco)
.Distinct()
.ToList();