I have a listview with data I don't know. I would like to delete a line after I press a button. The button is in the of the listview.
My code:
Xaml:
<MenuItem Clicked="SupprimerPoste_Clicked" CommandParameter="{Binding .}" />
my List:
public static ObservableCollection<Data> listePosteNoteFrais = new ObservableCollection<Data>();
App.listePosteNoteFrais.Add(new Data { Numero = Label_Numero.Text, ... });
event button:
private void SupprimerPoste_Clicked(object sender, EventArgs e)
{
var menuItem = ((MenuItem)sender);
Data delete ((Data)menuItem.CommandParameter
App.listePosteNoteFrais.Remove(delete);
}
CodePudding user response:
So you can try to remove the item in the data list in the clicked event of the button. You can check the following case which shows how to delete the item in the listview.
Case:How to remove an item from a Xamarin Forms ListView?
In addition, you can check the official document about how to use the observable collection as the listview's item resource.
Official document:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/data-and-databinding