• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

CListView & Appending Items :: MFC

kuphryn

Senior member
Hi.

I implemented a listview in a program. It works great, but not perfect. I have experience problems. First, the listview insert and display new item perfectly the if it was empty before insertion. For example.

// assume listview is empty

-----
CListView &lc = GetListCtrl();

for (int i = 0; i < 10; ++i)
lc.InsertItem(0, "testing");
-----

The code above will insert ten "testing" strings into the listview control. CListView will update the window with the ten items. However, let say that I want to add more items. Here is a technique I use.

-----
CListView &lc = GetListCtrl();
lc.DeleteAllItems();

int i;
for (i = 0; i < 10; ++i)
lc.InsertItem(i, "testing");

// inserting new lines

for (int j = i; i < 20; ++j)
lc.InsertItem(j, "new items");

Okay. The code above should work. However, sometimes CListView will not display the updated data. Again, in the example above, the program will not update the window with "new items." This seems to happen when I start to add a lot of items (100 or more). Is there some kind of a limit on the CListCtrl?

What is the proper way to add, remove, and clear a CListCtrl *and* properly redraw everything correctly?

Thanks,
Kuphryn
 
Have you tried Invalidate() once you've added all?
There's also a way to disable screen updates then re-enable them once you've added all your items, but I'd have to do some searching to track it down. LockWindowUpdates() or something like that.
 
Good point.

You were right. The reason it did not update the screen was because the window was focused. The solution is to redraw whenever the window is focus.

Kuphryn

 
Back
Top