how to change string inside dropdown

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

    • how to change string inside dropdown

      Hi everybody,
      I am trying to find a workaround to change string inside dropdown but at the moment I am far away from target.
      Since there is no API to change string directly (at least I did not find it) I am using DROPDOWN_GetListbox to get handle of the attached LISTBOX (DROPDOWN must be to get the handle back).
      I then change the string with LISTBOX_SetString and check with LISTBOX_GetItemText that string has been changed.

      ##############################

      hItem = WM_GetDialogItem(selectWindow, ID_DROPDOWN_0);
      DROPDOWN_Expand(hItem);
      if(DROPDOWN_GetListbox(hItem))
      {
      LISTBOX_SetString(DROPDOWN_GetListbox(hItem), text, i);
      LISTBOX_GetItemText(DROPDOWN_GetListbox(hItem), i, textItem, MAX_PATH_SIZE);
      }

      ##############################

      DROPDOWN widget show me new string until I made it collapse: after that widget show old string.
      Is there a trick to avoid this ?

      Regards,

      Paolo
    • Hello,

      DROPDOWN_InsertString() in conjunction with DROPDOWN_DeleteItem() can be used for this purpose.

      I'd do something like that:

      C Source Code

      1. #include "DIALOG.h"
      2. DROPDOWN_Handle hDropdown;
      3. BUTTON_Handle hButton;
      4. // Callback for background window as parent window for dropdown and button
      5. static void _cbBk(WM_MESSAGE * pMsg) {
      6. switch (pMsg->MsgId) {
      7. case WM_NOTIFY_PARENT:
      8. // If the button notifies background window of releasing it
      9. if ((pMsg->hWinSrc == hButton) && (pMsg->Data.v == WM_NOTIFICATION_RELEASED))
      10. {
      11. // Delete an old item with index 1
      12. DROPDOWN_DeleteItem(hDropdown, 1);
      13. // Insert a new item with index 1 and new text
      14. DROPDOWN_InsertString(hDropdown, "New_text1", 1);
      15. }
      16. break;
      17. case WM_PAINT:
      18. GUI_SetBkColor(GUI_LIGHTGRAY);
      19. GUI_Clear();
      20. break;
      21. default:
      22. WM_DefaultProc(pMsg);
      23. break;
      24. }
      25. }
      26. void MainTask(void) {
      27. GUI_Init();
      28. WM_MULTIBUF_Enable(1);
      29. // Set callback for background window
      30. WM_SetCallback(WM_HBKWIN, _cbBk);
      31. // Create a dropdown with 3 items
      32. hDropdown = DROPDOWN_CreateEx(80, 60, 80, 18, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_DROPDOWN0);
      33. DROPDOWN_AddString(hDropdown, "Old_text0");
      34. DROPDOWN_AddString(hDropdown, "Old_text1");
      35. DROPDOWN_AddString(hDropdown, "Old_text2");
      36. DROPDOWN_SetListHeight(hDropdown, 41);
      37. // Create a button for changing item text index 1
      38. hButton = BUTTON_CreateEx(200, 60, 80, 50, WM_HBKWIN, BUTTON_CF_SHOW, 0, GUI_ID_BUTTON0);
      39. BUTTON_SetText(hButton, "Change text 1");
      40. while(1)
      41. {
      42. GUI_Exec();
      43. }
      44. }
      Display All

      Alex.