TREEVIEW_GetItem() returns a wrong handle?

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

  • TREEVIEW_GetItem() returns a wrong handle?

    Hi,
    Sometimes
    TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
    returns its next sibling instead of 0 when hTreeItemCur hasn't any child..
    Sometimes it returns 0, sometimes it returns next sibling.
    Is there any solution? Is it a bug or my fault?

    I'm using stemwin on stm32f103zet6. (emwin version: 5.26)




    I extract the emwin related codes from loops. I explain the problem in detail;

    TREEVIEW_ITEM_Handle hTreeItemCur;
    TREEVIEW_ITEM_Handle hTreeItemNew;
    TREEVIEW_ITEM_Handle hTreeItemTemp;
    TREEVIEW_ITEM_Handle hTreeItemPreviousTemp;


    //firs operation, add a child to treeview item has only root node item.
    hItem = WM_GetDialogItem(hWin_FileWin, GUI_ID_TREEVIEW_0);
    hTreeItemCur = TREEVIEW_GetItem(hItem, 0, TREEVIEW_GET_FIRST); //Get Root node item

    hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
    // it hasn't any child.hTreeItemTemp = 0
    hTreeItemNew = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "1", 0);
    TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemCur, TREEVIEW_INSERT_FIRST_CHILD); TREEVIEW_ITEM_ExpandAll(hTreeItemCur);
    WM_Exec();

    //second operation, add a new next sibling item to previous node.
    hItem = WM_GetDialogItem(hWin_FileWin, GUI_ID_TREEVIEW_0);
    hTreeItemCur = TREEVIEW_GetItem(hItem, 0, TREEVIEW_GET_FIRST); //Get Root node item
    hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
    // it has a child. ( first child item text = "1" )
    hTreeItemPreviousTemp = hTreeItemTemp; //copy handle
    hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemTemp, TREEVIEW_GET_NEXT_SIBLING);
    // it hasn't next sibling. hTreeItemTemp = 0
    hTreeItemNew = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "2", 0);
    TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemPreviousTemp, TREEVIEW_INSERT_BELOW);
    //new sibling attached. ( new item text = "2" )
    TREEVIEW_ITEM_ExpandAll(hTreeItemCur);WM_Exec();
    //there is no problem so far. Now I will add a new child item to first node...
    hItem = WM_GetDialogItem(hWin_FileWin, GUI_ID_TREEVIEW_0);
    hTreeItemCur = TREEVIEW_GetItem(hItem, 0, TREEVIEW_GET_FIRST); //Get Root node item
    hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD); //first node item... hTreeItemCur = hTreeItemTemp; hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD); /*the problem is at here; first node hasn't child. It should return '0' but it returns second nodes handle (which has item text '2')....*/
    hTreeItemNew = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "1.1", 0);
    if(hTreeItemTemp) //if first item node has child, add a new child.
    { TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemTemp, TREEVIEW_INSERT_BELOW); }
    else // first node hasn't any child, add first child to first node...
    { TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemCur, TREEVIEW_INSERT_FIRST_CHILD); } TREEVIEW_ITEM_ExpandAll(hTreeItemCur);
    WM_Exec();


    When I change the sequence of operations there is no probem occur.
    first; add first node.
    second; add first child to first node.
    third; add second node.

    but I must generate nodes random sequence. Any Help?

    The post was edited 2 times, last by ilmete ().

  • Hi,

    Thanks for that information. We will check that behavior. From our point of view the function
    TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
    should return 0 if there is no child. But as a quick fix you can use the function TREEVIEW_ITEM_GetInfo(). It fills an information structure containing the 'level' of the item. If the level is the same as passed to TREEVIEW_GetItem() it should be the next sibling and not the first child.

    I hope that helps in the meantime.

    - Jörg
  • TREEVIEW - identify file selected

    Hi Jörg, I am completing my postgraduate completion of work, I'm doing an MP3-PLAYER with graphic display using EmWin, I managed to assemble the .mp3 files and show the screen with the TREEVIEW functions ...
    I could not identify files that are selected on the screen to send to an array if you can help me I appreciate it.

    PS. after presenting this project I intend to make it available as open source