1

I'm working on a VCL application in Delphi 10.3.3 and need to temporarily hide some rows (TListItem) in a TListView. Instead of deleting and re-adding the items, I want to make them invisible while still being able to access their values.

Is there a way to achieve this? How can I implement hide/show functionality for TListItems in TListView?

2 Answers 2

4

What you are asking for is not supported by the underlying Win32 LISTVIEW system control that TListView wraps. There is no per-item visibility or per-item heights. So, deleting and re-adding items is the only way to "hide" and "show" them.

For what you are attempting to accomplish, consider using the TListView in virtual mode (OwnerData=true). That way, your data is physically stored outside of the ListView's memory, so you can access it however you want regardless of how you setup the TListView to display it.

Otherwise, use a different UI control, such as TVirtualTreeView, which can be setup to look like a ListView, and has many advanced features to customize the display (such as per-node heights).

Sign up to request clarification or add additional context in comments.

3 Comments

Actually, I’m looking for a workaround. If I can’t find a solution, I’ll have to resort to using OwnerData := True.
I agree with Remy Lebeau. Using TListView in virtual mode is your best option as it gives you control of which items are shown and which are not.
TVirtualTreeView is a very good component as alternative - it even helps you with most of the detail problems that would come with TListView.OwnerData= TRUE. Do note that it melts in with TTreeView features, too (and expanding/collapsing a node can also be seen as "shown"/"hidden").
1

I've solved this by simply clearing the list and re-loading it. That's ok for shorter lists, but really long lists can have a noticeable delay. It's faster than going through the list and deleting / adding items, and you don't have to deal with things getting out-of-sync. I just make a method like UpdateUsersLV that does myUsersLV.Items.Clear; at the top and then regenerates it from scratch. (I forget if that even has an Items.Clear method, but if not then I just do it explicitly (between BeginUpdate and EndUpdate) from the bottom-up. Do NOT do it from the top-down!)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.