Sorting 如何对自定义类型的DataGridView进行排序
我试图根据分配给DataGridViewRow对象标记的自定义类(ERow)的值对DataGridView进行排序 我在实现IComparer方面的尝试如下所示: 类行比较器:IComparer { 公共int比较(DataGridViewRow x、DataGridViewRow y) { 然后,我尝试如下所示使用它,但编译器告诉我它无法从RowComparer转换为System.Collections.IComparer,这对我来说似乎很奇怪,因为我实际上实现了IComparer 排序(比较) 因此,出于绝望,我尝试了一个cast(见下文),但所做的只是将相同的错误从编译时转移到运行时 排序((IComparer)比较) 任何帮助都将不胜感激 提前谢谢 松鸦:-)Sorting 如何对自定义类型的DataGridView进行排序,sorting,datagridview,icomparer,Sorting,Datagridview,Icomparer,我试图根据分配给DataGridViewRow对象标记的自定义类(ERow)的值对DataGridView进行排序 我在实现IComparer方面的尝试如下所示: 类行比较器:IComparer { 公共int比较(DataGridViewRow x、DataGridViewRow y) { 然后,我尝试如下所示使用它,但编译器告诉我它无法从RowComparer转换为System.Collections.IComparer,这对我来说似乎很奇怪,因为我实际上实现了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);
}
}
}