private void dgvScanFai_SortCompare(object sender, DataGridViewSortCompareEventArgs e) { if (e.Column.Name == "Time") { string cellValue1 = e.CellValue1.ToString(); string cellValue2 = e.CellValue2.ToString(); // 提取出数字部分进行比较 int intCellValue1 = Convert.ToInt32(cellValue1.Split('-')[0]); int intCellValue2 = Convert.ToInt32(cellValue2.Split('-')[0]); // 比较数字部分的大小 e.SortResult = intCellValue1.CompareTo(intCellValue2); // 如果数字相同,则按照 ABC 部分进行比较 if (e.SortResult == 0) { string abcPart1 = cellValue1.Split('-')[1]; string abcPart2 = cellValue2.Split('-')[1]; e.SortResult = abcPart1.CompareTo(abcPart2); } e.Handled = true; } }
标签:string,自定义,C#,SortResult,DataGridView,Split,cellValue2,cellValue1 From: https://www.cnblogs.com/clx150401/p/17381184.html