NO

Author Topic: Listview wrong order  (Read 5013 times)

czerny

  • Guest
Listview wrong order
« on: December 06, 2014, 07:10:29 PM »
Hallo,

I am experimenting a little with listview controls.

I have the following resource:
Code: [Select]
CONTROL "", IDC_LV_3, "SysListView32", LVS_REPORT|LVS_SINGLESEL|LVS_AUTOARRANGE|WS_BORDER|WS_TABSTOP, 0, 0, 212, 141
and this code:
Code: [Select]
HICON hStan, hKyle, hCartman, hKenny;

// Set up the image list.
images = ImageList_Create(48, 48, ILC_COLOR8 | ILC_MASK, 4, 1 );

hStan = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_STAN), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT);
hKyle = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_KYLE), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT);
hCartman = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CARTMAN), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT);
hKenny = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_KENNY), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT);

ImageList_AddIcon(images, hStan);
ImageList_AddIcon(images, hKyle);
ImageList_AddIcon(images, hCartman);
ImageList_AddIcon(images, hKenny);

DeleteObject(hStan);
DeleteObject(hKyle);
DeleteObject(hCartman);
DeleteObject(hKenny);

ListView_SetImageList(hList, images, LVSIL_SMALL);

LV_COLUMN LvCol = {0};
LV_ITEM LvItem = {0};

LvCol.mask = LVCF_TEXT|LVCFMT_LEFT|LVCF_WIDTH; // Type of mask
LvCol.cx = 250; // width between each coloum
LvCol.pszText = "South Park"; // First Header Text

// Add column
SendMessage(hList,LVM_INSERTCOLUMN, 0, (LPARAM)&LvCol);
LvItem.mask   = LVIF_TEXT|LVIF_IMAGE;
LvItem.iImage = 0;
LvItem.pszText = "Stan Marsh";
ListView_InsertItem(hList, &LvItem);

LvItem.iImage = 1;
LvItem.pszText = "Kyle Brovlofsky";
ListView_InsertItem(hList, &LvItem);

LvItem.iImage = 2;
LvItem.pszText = "Eric Cartman";
ListView_InsertItem(hList, &LvItem);

LvItem.iImage = 3;
LvItem.pszText = "Kenny McCormick";
ListView_InsertItem(hList, &LvItem);

SendMessage(hList,LVM_SETCOLUMNWIDTH, 0, LVSCW_AUTOSIZE);
SendMessage(hList,LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);

But 'Stan' is not the first entry. The entrys are just in reverse order. What have I done wrong?

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Listview wrong order
« Reply #1 on: December 06, 2014, 08:16:06 PM »
Try taking away the LVS_AUTOARRANGE style.

czerny

  • Guest
Re: Listview wrong order
« Reply #2 on: December 06, 2014, 08:25:21 PM »
Try taking away the LVS_AUTOARRANGE style.
No, that is not the problem!

czerny

  • Guest
Re: Listview wrong order
« Reply #3 on: December 07, 2014, 01:58:20 PM »
The above problem is part of my translation of Neat Stuff to Do in List Controls Using Custom Draw in C code.
I have appended the whole project for you.

There is an other strange behaviour (see line 192). What is wrong here?

laurro

  • Guest
Re: Listview wrong order
« Reply #4 on: December 07, 2014, 03:57:48 PM »
czerny, for the first issue

Code: [Select]
// Add column
SendMessage(hList,LVM_INSERTCOLUMN, 0, (LPARAM)&LvCol);
LvItem.mask   = LVIF_TEXT|LVIF_IMAGE;
LvItem.iImage = 0;
LvItem.iItem = 0;//<-------here---------
LvItem.pszText = "Stan Marsh";
ListView_InsertItem(hList, &LvItem);

LvItem.iImage = 1;
LvItem.iItem = 1;//<-------here---------
LvItem.pszText = "Kyle Brovlofsky";
ListView_InsertItem(hList, &LvItem);

LvItem.iImage = 2;
LvItem.iItem = 2;//<-------here---------
LvItem.pszText = "Eric Cartman";
ListView_InsertItem(hList, &LvItem);

LvItem.iImage = 3;
LvItem.iItem = 3;//<-------here---------
LvItem.pszText = "Kenny McCormick";
ListView_InsertItem(hList, &LvItem);

but I don't understand the second question,
strange, how ?

Laur

czerny

  • Guest
Re: Listview wrong order
« Reply #5 on: December 07, 2014, 09:21:37 PM »
Code: [Select]
// Add column
SendMessage(hList,LVM_INSERTCOLUMN, 0, (LPARAM)&LvCol);
LvItem.mask   = LVIF_TEXT|LVIF_IMAGE;
LvItem.iImage = 0;
LvItem.iItem = 0;//<-------here---------
Oh, yes! Another silly error!

Thanks!