Sorting a Listview widget with bitmaps

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Sorting a Listview widget with bitmaps

    Hi,

    I'm having trouble sorting a LISTVIEW widget which has bitmaps set as the background of some cells.

    I have used LISTVIEW_SetItemBitmap() to set bitmaps in one column, and each row has a different bitmap. I have enabled sorting of the Listview.

    When I click on the header to re-sort the list, the rows are displayed in a different order - but the bitmaps don't relocate. Is there some action I need to take after a sort, to repaint the bitmaps in the correct row?

    Thanks for your help.
  • Hi,

    Thank you for sending the request. I will have a look at this and keep you informed. Would it be possible for you to provide me with a short sample code, so I can see how you implemented your LISTVIEW? This might be a help for me to find the cause of the problem.

    Best regards,
    Adrian
  • Ok, thanks for your help. Here's a simplified version of what we're trying to do. The icons placed in the first column don't change position when I sort based on the third column. The initial sort we do immediately after populating the list doesn't sort the icons either.

    Here's the init code:

    Source Code

    1. case WM_INIT_DIALOG:
    2. {
    3. // Set listview properties
    4. hItem = WM_GetDialogItem(hDlg, GUI_ID_LISTVIEW0);
    5. LISTVIEW_SetGridVis(hItem, 1);
    6. for (i = 0; i < 5; i++)
    7. {
    8. LISTVIEW_AddColumn(hItem, sTargetColumns[osdSizeIndex][i].Width,
    9. sTargetColumns[osdSizeIndex][i].pText,
    10. sTargetColumns[osdSizeIndex][i].Align);
    11. LISTVIEW_SetCompareFunc(hItem, i, sTargetColumns[osdSizeIndex][i].fpCompare);
    12. }
    13. LISTVIEW_EnableSort(hItem);
    14. // Enable sorting for the header
    15. hHeader = LISTVIEW_GetHeader(hItem);
    16. WM_SetCallback(hHeader, _cbHeader);
    17. break;
    18. }
    Display All

    And the code which populates the list:

    Source Code

    1. {
    2. WM_HWIN hListView;
    3. Int32 rowIdx = 0;
    4. UInt32 iconIdx;
    5. const GUI_BITMAP *pBitmap;
    6. char rankString[3];
    7. hListView = WM_GetDialogItem(hWin, GUI_ID_LISTVIEW0);
    8. iconIdx = 1;
    9. for(rowIdx = 0; rowIdx < 4; rowIdx++)
    10. {
    11. // Add a row to the listview
    12. LISTVIEW_AddRow(hListView, NULL);
    13. // Column 0: Icons
    14. switch (iconIdx)
    15. {
    16. case 1:
    17. pBitmap = &bmicon1;
    18. break;
    19. case 2:
    20. pBitmap = &bmicon2;
    21. break;
    22. case 3:
    23. pBitmap = &bmicon3;
    24. break;
    25. case 4:
    26. pBitmap = &bmicon4;
    27. break;
    28. default:
    29. pBitmap = &bmicon4;
    30. break;
    31. }
    32. LISTVIEW_SetItemBitmap(hListView, 0, rowIdx, 15, 1, pBitmap);
    33. // Column 1: target name
    34. LISTVIEW_SetItemText(hListView, 1, rowIdx, "Name");
    35. // Column 2: status
    36. LISTVIEW_SetItemText(hListView, 2, rowIdx, "Status");
    37. // Column 3: ranking
    38. snprintf(rankString, sizeof(rankString), "%ld", idx+1);
    39. LISTVIEW_SetItemText(hListView, 3, rowIdx, rankString);
    40. // Column 4: key
    41. LISTVIEW_SetItemText(hListView, 4, rowIdx, "F3");
    42. iconIdx++;
    43. }
    44. // Sort by ranking.
    45. LISTVIEW_SetSort(hListView, 3, 1);
    46. }
    Display All