zoukankan      html  css  js  c++  java
  • WPF ItemsSource Order by Getter

    public ObservableCollection<CustomerModel> CustomerCollection
    {
    get
    {
    if(customerCollection!=null)
    {
    var thirdList = customerCollection.ToList().OrderBy(x => x.RowGuid).ToList();
    customerCollection.Clear();
    foreach(var cus in thirdList)
    {
    customerCollection.Add(cus);
    }
    }
    return customerCollection;
    }
    set
    {
    customerCollection = value;
    OnPropertyChanged("CustomerCollection");
    }
    }

    private ICommand loadCmd;
    public ICommand LoadCmd
    {
    get
    {
    if(loadCmd==null)
    {
    loadCmd = new DelegateCommand<string>((obj) =>
    {
    FillDG();
    });
    }
    return loadCmd;
    }
    }

    private void FillDG()
    {
    List<CustomerModel> customerList = new List<CustomerModel>();
    string source = ConfigurationSettings.AppSettings["SqlSource"];
    SqlConnection conn = new SqlConnection(source);
    conn.Open();
    if(conn.State==ConnectionState.Open)
    {
    string sql = " select name,ProductNumber,rowguid from Production.Product";
    SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
    DataSet ds = new DataSet();
    sda.Fill(ds);
    if(ds.Tables[0].Rows.Count>0)
    {
    for(int i=0;i<ds.Tables[0].Rows.Count;i++)
    {
    customerList.Add(new CustomerModel()
    {
    Name = ds.Tables[0].Rows[i][0].ToString(),
    ProductName = ds.Tables[0].Rows[i][1].ToString(),
    RowGuid = ds.Tables[0].Rows[i][2].ToString()
    });
    }
    }
    }

    CustomerCollection = new ObservableCollection<CustomerModel>(customerList);
    }

  • 相关阅读:
    JavaIO学习:字符流
    Java学习:IO流
    Java中的Filter过滤器
    Java学习:File类中的过滤器接口
    Java学习:File类
    Java学习:递归
    多线程简介(全)
    Java学习:Lambda表达式
    Java学习:线程池
    Java学习:线程间通信
  • 原文地址:https://www.cnblogs.com/Fred1987/p/6238531.html
Copyright © 2011-2022 走看看