Suresh Rajana

Suresh Rajana

  • NA
  • 43
  • 6.6k

how to implement search bar in xamarin.forms

Mar 28 2017 2:07 AM
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; }
}
}
 

Answers (1)