public class BillsViewModel : ViewModelBase { private ICollectionView billsView; public ICollectionView BillsView { get { return billsView; } set { billsView = value; OnPropertyChanged("BillsView"); } } private ObservableCollection billss; public ObservableCollection Billss { get { return billss; } set { billss = value; OnPropertyChanged("Billss"); } } public static ObservableCollection Items { get; set; } = new ObservableCollection() { new Model(){ Name="Table2020" , ConStr="Data Source=test.db"}, new Model(){ Name="Table2021", ConStr= "Data Source=test1.db"}, }; public string selectedItem = Items.FirstOrDefault().ConStr; public string Tab1SelectedItem { get { return selectedItem; } set { if (selectedItem != value) { selectedItem = value; OnPropertyChanged("Tab1SelectedItem"); BillsView.Refresh(); Changed(); } } } public void Changed() { Billss.Clear(); Billss = GetAllBillsFromDB(); BillsView = CollectionViewSource.GetDefaultView(Billss); } public ObservableCollection GetAllBillsFromDB() { SQLiteConnection con = new SQLiteConnection(Tab1SelectedItem); con.Open(); SQLiteCommand cmd = new SQLiteCommand("Select * From billdata", con); SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); var Bills = new ObservableCollection(); foreach (DataRow dr in dt.Rows) { var p = (dr["PaidOn"] == DBNull.Value) ? String.Empty : (string)(dr["PaidOn"]); var q = (dr["Remarks"] == DBNull.Value) ? String.Empty : (string)(dr["Remarks"]); Bills.Add(new Bills { Id = Convert.ToInt32(dr[0].ToString()), Party = dr[1].ToString(), BillNo = (string)dr["BillNo"], BillDt = (string)(dr["BillDt"]), Amt = (string)(dr["Amt"]), DueDt = (string)(dr["DueDt"]), PaidOn = p, Remarks = q }); } con.Close(); return Bills; } public BillsViewModel() { Billss = GetAllBillsFromDB(); BillsView = CollectionViewSource.GetDefaultView(Billss); } }