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; }; }