Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 如何对自定义类型的DataGridView进行排序_Sorting_Datagridview_Icomparer - Fatal编程技术网

Sorting 如何对自定义类型的DataGridView进行排序

Sorting 如何对自定义类型的DataGridView进行排序,sorting,datagridview,icomparer,Sorting,Datagridview,Icomparer,我试图根据分配给DataGridViewRow对象标记的自定义类(ERow)的值对DataGridView进行排序 我在实现IComparer方面的尝试如下所示: 类行比较器:IComparer { 公共int比较(DataGridViewRow x、DataGridViewRow y) { 然后,我尝试如下所示使用它,但编译器告诉我它无法从RowComparer转换为System.Collections.IComparer,这对我来说似乎很奇怪,因为我实际上实现了IComparer 排序(比较

我试图根据分配给DataGridViewRow对象标记的自定义类(ERow)的值对DataGridView进行排序

我在实现IComparer方面的尝试如下所示:

类行比较器:IComparer { 公共int比较(DataGridViewRow x、DataGridViewRow y) {

然后,我尝试如下所示使用它,但编译器告诉我它无法从RowComparer转换为System.Collections.IComparer,这对我来说似乎很奇怪,因为我实际上实现了IComparer

排序(比较)

因此,出于绝望,我尝试了一个cast(见下文),但所做的只是将相同的错误从编译时转移到运行时

排序((IComparer)比较)

任何帮助都将不胜感激

提前谢谢

松鸦:-)

        ERow xRow = (ERow)x.Tag;
        ERow yRow = (ERow)y.Tag;
        if (xRow.Group != yRow.Group)
        {
            return xRow.Group.CompareTo(yRow.Group);
        }
        else
        {
            // Check if either row is a header and sort it to the top,regardless of Sort
            if (xRow.IsHeader)
            { return -1; }

            if (yRow.IsHeader)
            { return 1; }

            // If all else fails, sort these two based on the SortOrder property.
            return xRow.SortOrder.CompareTo(yRow.SortOrder);
        }
    }
}