我在 datagridview 中有带有数字的字符串列。它没有绑定,我想按我使用的数字对其进行排序
colid.ValueType = typeof(int);
grid.Sort(colid, ListSortDirection.Descending);
但有点像字符串,例如:
11
12
23
7
80
81
而预期是
7
11
12
23
80
81
您可以在SortCompare
事件,例如:
private void customSortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
int a = int.Parse(e.CellValue1.ToString()), b = int.Parse(e.CellValue2.ToString());
// If the cell value is already an integer, just cast it instead of parsing
e.SortResult = a.CompareTo(b);
e.Handled = true;
}
...
yourGridview.SortCompare += customSortCompare;
...
我没有检查这是否有效,但你明白了......;)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)