Forum Cross Platform with Xamarin

ListView Not updating after deleting item

Hello everyone. I am trying to delete listview item. The item it self deletes from the database fine but the list view doesn't update, I am even using an observableCollection. This is my code:

`public partial class MainPage : ContentPage
DatabaseCRUDOperations dcr = new DatabaseCRUDOperations();

    public MainPage()


    protected override void OnAppearing()
        listUsers.ItemsSource = dcr.GetUsers();

    private void Delete_Clicked(object sender, EventArgs e)
        var user = (sender as MenuItem).CommandParameter as UserModel;

    private void Handle_Clicked(object sender, EventArgs e)
        Navigation.PushAsync(new UserRegistrationView());

This is the Xaml file for mainpage:

` <ContentPage.ToolbarItems>






`public class DatabaseCRUDOperations
//the connection
private static SQLiteConnection _connection;

    //Create database
    public DatabaseCRUDOperations()
        //get the connection for independent platform
        _connection = DependencyService.Get<SQLiteDb>().GetConnection();

        //create table in database


    //Get the users from the database
    public ObservableCollection<UserModel> GetUsers()
      //  IEnumerable<UserModel> user = _connection.Table<UserModel>().ToList();
        ObservableCollection<UserModel> user = new ObservableCollection<UserModel>(_connection.Table<UserModel>().ToList());
        return user;

    //Add member to the database
    public string AddMember(UserModel _user)
        //Access the DB and add the user
        return "Successfully added member!";

    //Delete user from the database
    public string DeleteMember(int id)
        //Access the DB and delete the user at this ID

        return "Successfully deleted member!";


` [Table("UserModel")]
public class UserModel
[PrimaryKey, AutoIncrement]
public int ID { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }


public interface SQLiteDb { SQLiteConnection GetConnection(); }

` public partial class UserRegistrationView : ContentPage, INotifyPropertyChanged
public DatabaseCRUDOperations userDatabase;
public UserModel user;

    public UserRegistrationView ()
        InitializeComponent ();

    public void Save_Clicked(object o, EventArgs e)
        user = new UserModel
            FirstName = fname.Text,
            LastName = lname.Text

        userDatabase = new DatabaseCRUDOperations();




  • Ahsan_SiddiqueAhsan_Siddique PKMember ✭✭✭✭

    you need to create a load function on delete button event that reload your list.

Sign In or Register to comment.