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;//再绑定