Discussion:
ListView: delete column "id" vs "index" API strangeness?
(too old to reply)
davecotter
2010-05-19 17:47:01 UTC
Permalink
say i create a list view with column "id"s [0, 1, 2, 3]

now, in my back end, i've created a "map" so that i know that ID 0 maps to
say "track number", 1 maps to "song name", 2 "artist name" and 3 is "album
name". sound good?

now say the user reorders the columns, such that a call to
GetColumnOrderArray() returns [0, 1, 3, 2]

so now my "map" says "track, song name, album name, artist name", right?
cuz now 3 comes before 2. so far so good.

now, what if the user decides to hide the artist name? (that would be ID 2,
which is NOW at index 3!)

so i call DeleteColumn() with INDEX 3 (note: this API does not take the ID,
but the index, or the left-to-right order of visual appearance)

you might think that the array would now be [0, 1, 3], right? no, you'd be
wrong about that. for some reason i am totally unable to fathom, the array
is *renumbered* to [0, 1, 2], so unless i change my map to say "by the way 2
now points to what 3 used to point to", i'm screwed.

what is really going on here? what am i missing? what is the strategy
people usually use?
Timo Kunze
2010-05-19 18:24:49 UTC
Permalink
Post by davecotter
what is really going on here? what am i missing? what is the strategy
people usually use?
Where did you read that the column indexes would be IDs? MSDN talks
about indexes and positions, not about IDs. And as you probably know,
indexes can change.

Timo
--
www.TimoSoft-Software.de - Unicode controls for VB6
"Those who sacrifice freedom for safety deserve neither."
"Demokratie ist per Definition unsicher. Ihr Schutz entsteht aus der
Überzeugung, dass die demokratischen Kräfte überwiegen und sich – auf
demokratischem Wege – durchsetzen."
dave
2010-05-19 19:47:52 UTC
Permalink
telling me i'm doing it wrong is redundant, since i came here with
that assumption. "helpful" <-> "silent": pick one.
Timo Kunze
2010-05-19 20:46:37 UTC
Permalink
Post by dave
telling me i'm doing it wrong is redundant, since i came here with
that assumption. "helpful" <-> "silent": pick one.
Well, you asked what you're missing and I gave you the answer. ;)

If you really need an ID, you probably can use the lParam member of the
HDITEM struct.

Timo
--
www.TimoSoft-Software.de - Unicode controls for VB6
"Those who sacrifice freedom for safety deserve neither."
"Demokratie ist per Definition unsicher. Ihr Schutz entsteht aus der
Überzeugung, dass die demokratischen Kräfte überwiegen und sich – auf
demokratischem Wege – durchsetzen."
davecotter
2010-05-19 23:33:01 UTC
Permalink
that is the info i needed. :D we thankses you, precious!
davecotter
2010-05-20 00:33:01 UTC
Permalink
excellent. however, i'm still missing something. so, right after i make
this call:

ListView_InsertColumn(listH, i_colMap.size(), &colRec);

i then do this:

HWND headerH = ListView_GetHeader(listH);
HDITEM itemRec; structclr(itemRec);

itemRec.mask = HDI_LPARAM | HDI_ORDER | HDI_FORMAT;

if (Header_GetItem(headerH, colIndexL, &itemRec)) {
CF_ASSERT(itemRec.iOrder == colRec.iOrder);

itemRec.lParam = colDesc.propertyDesc.propertyID;
// itemRec.fmt = HDF_SORTUP; sort ascending or descending

if (!Header_SetItem(headerH, colIndexL, &itemRec)) {
handle failz

however, ListView_GetHeader() returns NULL. there is no header??
davecotter
2010-05-20 16:36:05 UTC
Permalink
i got it working. i was accidentally operating on a treeview not a listview.
Loading...