July 12th, 2004

Positioned vs. non-positioned listview views

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?

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.