we are working on xamrin.forms shared application, i want to implement search bar activity in my project
i have sample code for the implemetation here
public partial class MainPage : ContentPage
{
public class LVsearItem
{
public string SName
{
get;
set;
}
}
private readonly ObservableCollection<LVsearItem> Iitem;
public MainPage()
{
InitializeComponent();
ObservableCollection<LVsearItem> items = new ObservableCollection<LVsearItem>();
items.Add(new LVsearItem()
{
SName = "raghu"
});
items.Add(new LVsearItem()
{
SName = "vicky"
});
items.Add(new LVsearItem()
{
SName = "singmodel"
});
items.Add(new LVsearItem()
{
SName = "ravi"
});
items.Add(new LVsearItem()
{
SName = "raju"
});
items.Add(new LVsearItem()
{
SName = "phateal"
});
items.Add(new LVsearItem()
{
SName = "nayaksing"
});
Iitem = items;
lvSearch.ItemsSource = Iitem;
}
private void FilterNames()
{
string filter = searching.Text;
lvSearch.BeginRefresh();
if (string.IsNullOrWhiteSpace(filter))
{
lvSearch.ItemsSource = Iitem;
}
else
{
lvSearch.ItemsSource = Iitem.Where(x => x.SName.ToLower().Contains(filter.ToLower()));
}
lvSearch.EndRefresh();
}
void OnSearchBarTextChanged(object sender, TextChangedEventArgs args)
{
FilterNames();
}
void OnSearchBarButtonPressed(object sender, EventArgs args)
{
FilterNames();
}
her items are add from "items.Add(new LVsearItem()"but i want add these itams from my database table.
while items are searched in search bar it will redirected from databse table
how to do this
//database table //
public Doctors()
{
}
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
[MaxLength(25)]
public string Name { get; set; }
[MaxLength(40)]
public string Specialization { get; set; }
[MaxLength(40)]
public string Username { get; set; }
[MaxLength(40)]
public string Email { get; set; }
[MaxLength(40)]
public int Phoneno { get; set; }
[MaxLength(20)]
public string Password { get; set; }
[MaxLength(30)]
public string Confirmpassword { get; set; }
[MaxLength(30)]
public string Address { get; set; }
}
}