ObservableCollection通过Move方法可以移动顺序,如下:

将ObservableCollection中的一个item置顶:

private ObservableCollection<GroupListInfo> _disCussItems;
private void TopItem(string groupName)
{
var info = _disCussItems.FirstOrDefault(m => m.GroupName == groupName);
if (info == null) return;
var index = _disCussItems.IndexOf(info);
if (index < ) return;
_disCussItems.Move(index, );
}

但是当ObservableCollection分组后,

var vw = CollectionViewSource.GetDefaultView(_disCussItems);

vw.GroupDescriptions.Add(new PropertyGroupDescription("TimeGroup"));//按TimeGroup字段分组

Move方法就会出现错误,

大概猜测排序后每个组的index都是在各自的组内,最后只能做一个兼容的操作:

就是在调用Move方法之前,先清空分组;

待move方法完成后,在调用分组功能,具体如下:

private ObservableCollection<GroupListInfo> _disCussItems;
private void TopItem(string groupName)
{
var info = _disCussItems.FirstOrDefault(m => m.GroupName == groupName);
if (info == null) return;
var vw = CollectionViewSource.GetDefaultView(_disCussItems);
vw.GroupDescriptions.Clear();
var index = _disCussItems.IndexOf(info);
if (index < ) return;
_disCussItems.Move(index, );
vw.GroupDescriptions.Add(new PropertyGroupDescription("TimeGroup"));
}

ObservableCollection 分组后排序报错问题的更多相关文章

  1. 排序(分组后排序&整排)

    一.整排 要求:根据score进行排名,分数相同,名次相同,且连续 表如下图: sql语句: 方法一:select a.score, (select count(distinct b.score) f ...

  2. ES使用text类型字段排序报错

    elasticsearch text字段排序报错解决使用elasticsearch 进行排序的时候,我们一般都会排序数字.日期.但是在排序text类型的时候就会出现错误. GET xytest/sut ...

  3. dialogic d300语音卡驱动重装后启动报错问题解决方法

    dialogic d300 驱动重装后 dlstart  报错解决 问题描述:dlstart  后如下报错 [root@BJAPQ091 data]#dlstop Stopping Dialogic ...

  4. Heka 编译安装后 运行报错 panic: runtime error: cgo argument has Go pointer to Go pointer

    Heka 编译安装后 运行报错 panic: runtime error: cgo argument has Go pointer to Go pointer 解决办法: 1.  Start heka ...

  5. 安装mongodb后启动报错libstdc++

    安装mongo后启动报错如下图 显然说是libstdc++.so文件版本的问题,这种一般都是gcc版本太低了 接着查询gcc的版本    strings /usr/lib/libstdc++.so.6 ...

  6. Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL

    Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL     严重: Error config ...

  7. linux上安装完torch后仍报错:ImportError: No module named torch

    linux上安装完torch后仍报错: Traceback (most recent call last): File , in <module> import torch ImportE ...

  8. 安卓工作室 android studio 汉化后,报错。 设置界面打不开。Can't find resource for bundle java.util.PropertyResourceBundle, key emmet.bem.class.name.element.separator.label

    安卓工作室 android studio 汉化后,报错. 设置界面打不开. Android studio has been sinified and reported wrong.The setup ...

  9. Python首次安装后运行报错(0xc000007b)的解决方法

    最近在安装完Python后运行发现居然报错了,错误代码是0xc000007b,于是通过往上查找发现是因为首次安装Python缺乏VC++库的原因,下面通过这篇文章看看如何解决这个问题吧.   错误提示 ...

随机推荐

  1. inline 元素的特性

    http://www.maxdesign.com.au/articles/inline/ http://www.w3.org/TR/CSS2/visuren.html#inline-boxes htt ...

  2. Linux 上关于iptables

    有几个命令: 1.service iptables staus   2.service iptables start    3.service iptables restart   有个配置文件/ec ...

  3. SPFA 算法(剪辑)(学习!)

    SPFA算法 单源最短路径的算法最常用的是Dijkstra,些算法从时间复杂度来说为O(n^2),但是面对含有负权植的图来说就无能为力了,此时 Dellman-ford算法就有用了,这咱算法是采用的是 ...

  4. 算法(Algorithms)第4版 练习 1.3.1

    package com.qiusongde; import java.util.Iterator; import java.util.NoSuchElementException; import ed ...

  5. 学习HTML5

    CSS,层叠样式表,能为网页增添样式的电脑语言. UL属于无序列表 OL属于有序列表 DL属于自定义列表.

  6. idea中java异常

    1. Compilation failed: internal java compiler error 解决方案:File-->Setting...-->Build,Execution,D ...

  7. 分享知识-快乐自己:反射机制Demo解析

    Java-Reflect专题 基本反射简介: 1):JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象能够调用它的任意方法和属性;这种动态获取信息以及动 ...

  8. node.js+express+jade系列六:图片的上传

    安装npm install formidable 先把文件上传到临时文件夹,再通过fs重命名移动到指定的目录即可 fs.rename即重命名,但是fs.rename不能夸磁盘移动文件,所以我们需要指定 ...

  9. 动态规划 两个字符串之间的编辑距离 leetcode72

    public static int minDistance(String word1, String word2) { char[] s1 = word1.toCharArray(); char[] ...

  10. IDEA-Eclipse结构项目转移到 Idea教程

    1.确定Idea的svn配置 2.从svn导出项目 3.检出项目完成,开始设置 4.配置完成,设置svn忽略文件,忽略掉idea配置文件等 5. 设置完毕