数据源的排序

 

 

dataview类型的用sort排序,

自定义数据源:

DataTable tb = new DataTable();
tb.Columns.Add("name");
tb.Columns.Add("age");
tb.Rows.Add("张三","18");
tb.Rows.Add("李四","17");
tb.Rows.Add("王五", "19");
tb.Rows.Add("小明", "16");

DataView dv = tb.DefaultView;
listview.ItemsSource = dv;

排序:

((DataView)listview.ItemsSource).Sort="age";

 

数据源为ObservableCollection

ObservableCollection <DtsInterfaceItemInfo> list = this.listview.ItemsSource as ObservableCollection<DtsInterfaceItemInfo>;

排序:

list = new ObservableCollection<DtsInterfaceItemInfo>(list.OrderBy(s => s.ItemType));
this.listview.ItemsSource = list;//再绑定

posted @ 2019-04-30 11:33  岳凯歌  阅读(147)  评论(0编辑  收藏  举报