What is the purpose of LVCOLUMN.iSubItem?

I do not understand what the purpose of LVCOLUMN.iSubItem . This is what MSDN says:

iSubItem

 Type: int Index of subitem associated with the column. 

At first I thought that this means that when I create a column, I can set the index to the column, for example: 123, and then when I want to insert some data into the column, I just put the number 123 as the identity of the column.

But this does not work, no matter what indexes I set in the columns, the columns are still numbered 0, 1, 2, 3, ...

+6
source share
3 answers

No, LVCOLUMN.iSubItem numbered sequentially from 0, from left to right, as you know. Yes, of course, it seems that this is not practical, since you should always specify the column number in order to do something with LVCOLUMN. Therefore, he simply returns to you what you already know.

It is hard to guess how this happened, except to note that the common controls were not exactly Microsoft. I suspect this might be related to LVS_EX_HEADERDRAGDROP in the list. This allows the user to reinstall columns by dragging and dropping them. Now the column index you pass to LVM_GETCOLUMN is a bit muddy, should you indicate the position or source column index? They went with the latter and used LVM_GETCOLUMNORDERARRAY if you need to know how the user arranged the columns.

Or they just mirror LVITEM.iSubItem so that the structures look similar, perhaps a little more likely. Do not worry about it.

+4
source

The subclause is valid and valid only for list controls in the LVS_REPORT style. You need to insert columns in order to use it.

In this style, you add LVM_INSERTITEM elements, and each element can have subitems. To access the contents of a subitem, you need a member of the structure.

+1
source

If you use the LVS_REPORT style, the list control looks like a grid control.

In this case, the items are stored in column 0, and the subitems represent what is stored in other columns (there is no whole concept such as a "cell"). Thus, the subitem index is noticeably used with LVM_SETITEM and LVM_GETITEM (or with the corresponding ListView_SetItem and ListView_GetItem macros), for example, to write or read the text value of column X. Depending on the index, you get access to the element if iSubItem == 0 or a subitem. if iSubItem> = 1.

You can look at this question here on SO for an additional sample: Elements and sub-elements in a List-View control

+1
source

Source: https://habr.com/ru/post/986282/


All Articles