hamid.sh
hamid.sh

Reputation: 1066

How to add invisible items to ListView in C#?

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 columns to the listview to store extra values in it? Or bind some extra items to listview items?

Upvotes: 1

Views: 2776

Answers (3)

hamid.sh
hamid.sh

Reputation: 1066

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...

Upvotes: 1

Robert Levy
Robert Levy

Reputation: 29083

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

Upvotes: 0

WraithNath
WraithNath

Reputation: 18013

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

Upvotes: 1

Related Questions