Positioned vs. non-positioned listview views

Raymond Chen

Raymond

Occasionally, I’ll see a question that betrays a lack of understanding of difference between the positioned and non-positioned listview views. The question usually goes along the lines of “I inserted an item with LVM_INSERTITEM but it went to the end of the list instead of in the location I inserted it.”
To understand what is going on, you need to know that some listview views are “positioned” and others are “non-positioned”.
“(Large) icon view”, “small icon view”, and “tile view” are positioned views. Each item carries its own coordinates, which you can customize via LVM_SETITEMPOSITION. When a new item is inserted, it gets an item index based on the insertion point, but its physical location on the screen is the first available space not already occupied by another item. Existing items are not moved around to make room for the inserted item.
The other views, “list view” and “report (aka details) view”, are non-positioned views. In these views, items do not get to choose their positions. Instead, the position of an item is determined by its item index. In non-positioned views, inserting or deleting an item will indeed cause all subsequent items to shift.

Now you can answer the question. Why did the item go to the end of the list instead of at the position the caller inserted it?

Raymond Chen
Raymond Chen

Follow Raymond   

0 comments

Comments are closed.