I'm going to develop a project which interacts with files and folders through a ListView control in the program's UI. I've added a custom sort method to the listview to sort items according to its different columns. There are some columns in the listview like Size and Date. Size column contains the shortened size value, e.g. "1.9 MB" instead of "2000000" bytes, so it's impossible to sort the listview items by the shortened size values and obtain the expected result.
Is there any way to add some invisible co开发者_运维百科lumns to the listview to store extra values in it? Or bind some extra items to listview items?
You cant have invisible columns but you could set the width of the columns you dont want to show to 0. This way they would not show up unless a user tried to resize the column next to it. Visually a user would now know its there
Sometimes simple things become so complicated. I've got it... An easy and handy solution...
Actually it is possible to have hidden items as easy as having more subitems than columns. E.g. having 6 subitems and 4 columns means that we have 2 "hidden" subitems. The only remaining thing is redirecting the sort procedure to these sortable hidden subitems (columns).
Thanks to WraithNath & Robert Levy...
you could solve this problem without the hidden columns by customizing how sorting is done.
for winforms: http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemsorter.aspx
for wpf: http://msdn.microsoft.com/en-us/library/system.componentmodel.sortdescription.aspx
精彩评论