How to hide a column in TListview?
Asked Answered
K

1

6

I am using a listview to store and show data. How can i hide and show a column in listview? Dont tell me to set the column width to 0 please!!!!

Kokoruda answered 15/6, 2011 at 12:30 Comment(6)
I don't think there is any automatic way of doing this. Instead, I think you have to remove the Column from the Columns property and then update all the subitems. If you do 'non-trivial' things and have a lot of data to present, I think it is a good idea to use the list view in virtual mode. Then things like this are done in a more natural way.Sedberry
@Andreas I wrote my answer before reading your comment just in case you think I simply stole your idea and tried to gain some rep on the back of it!Hawking
@Armin Deleting is something else then hiding. You asked for hiding and again showing. Is the reason you don't want any answer with setting Width to 0 because setting Width doesn't work? If so, then may I suggest to use ListView_SetColumnWidth (CommCtrl) which dóes work!Dodgson
@NGLN: You cannot hide a column by setting its with to zero. Try this: Add three columns: A, B, and C. Set the width of B to zero. Then only A and C are shown, indeed. But: now try to make column A wider by dragging the 'separator' between A and C. You expect A to get wider, but instead the width of A remains constant and B is being shown!Sedberry
@Andreas I knew, hence the "If so, " and hence a comment, not an answer. (Phew, the incompleteness of even my comments is dragging me.. ;-))Dodgson
@NGLN: Good, you scared me there for a while! ;)Sedberry
H
7

In the Delphi TListView you can't hide columns in vsReport view style. Your only option is to delete the column when you need to hide it, and create it again when you need to show it.

This is yet another example of why virtual list views are much more desirable than non-virtual list views. With a virtual list view you can insert new columns without having to iterate across all items in the list and re-populate their sub items.

Hawking answered 15/6, 2011 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.