CListView & Appending Items :: MFC

kuphryn

Senior member
Jan 7, 2001
400
0
0
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
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
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.
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
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