public class ViewModel : INotifyPropertyChanged { SqlConnection con; SqlCommand cmd; SqlDataAdapter adapter; DataSet ds; public static ObservableCollection Items { get; set; } = new ObservableCollection() { new Model(){ Name="Table2020" , ConStr=@"constr1"}, new Model(){ Name="Table2021", ConStr= @"constr1"}, new Model(){ Name="Table2022", ConStr= @"constr1"}, }; private string selectedItem = Items.FirstOrDefault().ConStr; public string SelectedItem { get { return selectedItem; } set { if (selectedItem != value) { selectedItem = value; OnPropertyChanged("SelectedItem"); Changed(); } } } public void Changed() { Bills.Clear(); Bills = GetDatas(); BillsView = CollectionViewSource.GetDefaultView(Bills); } private ICollectionView billsView; public ICollectionView BillsView { get { return billsView; } set { billsView = value; OnPropertyChanged("BillsView"); } } private ObservableCollection bills; public ObservableCollection Bills { get { return bills; } set { bills = value; OnPropertyChanged("Bills"); } } public ObservableCollection GetDatas() { con = new SqlConnection(SelectedItem); con.Open(); cmd = new SqlCommand("select * from [dbo].[BillData]", con); adapter = new SqlDataAdapter(cmd); ds = new DataSet(); adapter.Fill(ds, "[dbo].[BillData]"); var Bills = new ObservableCollection(); foreach (DataRow dr in ds.Tables[0].Rows) { Bills.Add(new Bill { Id = Convert.ToInt32(dr[0].ToString()), Party = dr[1].ToString(), }); } con.Close(); return Bills; } public ViewModel() { Bills =GetDatas(); BillsView = CollectionViewSource.GetDefaultView(Bills); } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string name = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } } public class Bill { public int Id { get; set; } public string Party { get; set; } } public class Model : INotifyPropertyChanged { private string name; public string Name { get { return name; } set { if (name != value) { name = value; OnPropertyChanged("Name"); } } } private string conStr; public string ConStr { get { return conStr; } set { if (conStr != value) { conStr = value; OnPropertyChanged("ConStr"); } } } public Model(){} public Model(string constr){} public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string name = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } }