111,120
社区成员
发帖
与我相关
我的任务
分享 <CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="字段名"/>
</CollectionViewSource.SortDescriptions>
/// <summary>
/// 自定义排序比较器
/// </summary>
sealed public class MyComparer : System.Collections.IComparer
{
int System.Collections.IComparer.Compare(Object x, Object y)
{
String strX = x.ToString();
String strY = y.ToString();
if (strX.Length > strY.Length)
{
return 1;
}
else if (strX.Length < strY.Length)
{
return -1;
}
else
{
return System.String.Compare(strX, strY);
}
}
}dataGridView1.Sort(new MyComparer());