其他分享
首页 > 其他分享> > DataGridView列排序

DataGridView列排序

作者:互联网

调用

DataGridView1.BindSortCompare()

 

公共类

public static void BindSortCompare(this DataGridView dg)
        {
            dg.SortCompare += (s, e) =>
            {
                double value1, value2;

                if (!double.TryParse(e.CellValue1?.ToString(), out value1))
                    return;
                if (!double.TryParse(e.CellValue2?.ToString(), out value2))
                    return;

                if (value1 == value2)
                    e.SortResult = 0;
                else if (value1 < value2)
                    e.SortResult = -1;
                else
                    e.SortResult = 1;

                e.Handled = true;
            };
        }

 

标签:double,SortResult,DataGridView,value2,value1,排序,out,BindSortCompare
来源: https://www.cnblogs.com/zhaotiantian/p/16182336.html