简体   繁体   中英

Datagridview - custom sort on column

I have a DGV with a column named 'Position'. The 'Position' column contains positive and negative values.

Eg: -2 -1 1 2 3 ... 200

Basically, I'd like a nice way to have the negative numbers appear after the positive numbers, with the negative numbers "increasing", so like this:

1 2 3 ... 199 200 -1 -2 -3

I'm sure I can hack together some ugly for loop, but there must be a better way.

Appreciate any help, Cheers!

您可以使用linq查询

items.OrderBy(x => x.Position >= 0).ThenBy(x => x.Position < 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM