may I know how to make the rows of my table can be swipe to delete or pop out a "red stop" button to allow user to delete the inserted data?
Below attached with the code of my Table ViewController cs file that only displays all data in table list :
*The view controller is created using storyboard, not by code.
using Foundation;
using System;
using UIKit;
using SQLite;
using System.Collections.Generic;
using System.IO;
namespace One
{
public partial class StudentDataBaViewController : UITableViewController
{
private string pathToDatabase;
private List<Student> students;
public StudentDataBaViewController (IntPtr handle) : base (handle)
{
students = new List<Student>();
}
//connect to student_da.db database file and create a table named Student
public override void ViewDidLoad()
{
base.ViewDidLoad();
//path of the database
var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
pathToDatabase = Path.Combine(documentsFolder, "student_db.db");
//connect database and create table
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
connection.CreateTable<Student>();
}
}
//used to relaod or update new elements entered on the list
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
students = new List<Student>();
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
var query = connection.Table<Student>();
foreach (Student student in query)
{
students.Add(student);
TableView.ReloadData();
}
}
}
public override nint RowsInSection(UITableView tableView, nint section)
{
return students.Count;
}
//make elements to be display on the database list
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell("student");
var data = students[indexPath.Row];
cell.TextLabel.Text = data.StudentName;
cell.DetailTextLabel.Text = data.StudentId;
return cell;
}
public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
{
return true;
}
}
public class Student
{
[PrimaryKey]
public string StudentId
{
get;
set;
}
public string StudentName
{
get;
set;
}
public string StudentPassword
{
get;
set;
}
public bool StudentAttendence
{
get;
set;
}
}
}