LISTVIEW Get All data to buffer and Set again

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

    • LISTVIEW Get All data to buffer and Set again

      Dear,

      i have a listbox. so i want to save listbox datas to save file and restore again.
      When this code runs ,

      Source Code

      1. int numOfRead = LISTVIEW_GetUserData(hListview,fContect,memsize);
      2. PRINTF("numOfRead:%d.\n",numOfRead);

      it prints 0. i cant find get all data from listview. and restore it again. can you suggest any solition?

      my orginal source code is:

      C Source Code

      1. /*********************************************************************
      2. * SEGGER Microcontroller GmbH *
      3. * Solutions for real time microcontroller applications *
      4. **********************************************************************
      5. * *
      6. * (c) 1996 - 2022 SEGGER Microcontroller GmbH *
      7. * *
      8. * Internet: www.segger.com Support: support@segger.com *
      9. * *
      10. **********************************************************************
      11. ** emWin V6.24 - Graphical user interface for embedded applications **
      12. emWin is protected by international copyright laws. Knowledge of the
      13. source code may not be used to write a similar product. This file may
      14. only be used in accordance with a license and should not be re-
      15. distributed in any way. We appreciate your understanding and fairness.
      16. ----------------------------------------------------------------------
      17. File : LISTVIEW_Usage.c
      18. Purpose : Sample that demonstrates the usage of LISTVIEW widgets
      19. in emWin.
      20. Requirements: WindowManager - (x)
      21. MemoryDevices - ( )
      22. AntiAliasing - ( )
      23. VNC-Server - ( )
      24. PNG-Library - ( )
      25. TrueTypeFonts - ( )
      26. Wiki link : https://wiki.segger.com/LISTVIEW_-_Usage_(Sample)
      27. ---------------------------END-OF-HEADER------------------------------
      28. */
      29. #include "DIALOG.h"
      30. #include <stdio.h>
      31. #include <stdlib.h>
      32. /*********************************************************************
      33. *
      34. * Defines
      35. *
      36. **********************************************************************
      37. */
      38. #define ID_COLUMN_EMP_NO 0
      39. #define ID_COLUMN_LAST_NAME 1
      40. #define ID_COLUMN_FIRST_NAME 2
      41. #define ID_COLUMN_EXT 3
      42. #define ID_COLUMN_TITLE 4
      43. #define ID_COLUMN_EMAIL 5
      44. /*********************************************************************
      45. *
      46. * Static data
      47. *
      48. **********************************************************************
      49. */
      50. static const char * _acContent[][6] = {
      51. { "1002", "Murphy", "Diane", "x5800", "President", "dmurphy@classicmodelcars.com" },
      52. { "1056", "Patterson", "Mary", "x4611", "VP Sales", "mpatterso@classicmodelcars.com" },
      53. { "1076", "Firrelli", "Jeff", "x9273", "VP Marketing", "jfirrelli@classicmodelcars.com" },
      54. { "1088", "Patterson", "William", "x4871", "Sales Manager (APAC)", "wpatterson@classicmodelcars.com" },
      55. { "1102", "Bondur", "Gerard", "x5408", "Sale Manager (EMEA)", "gbondur@classicmodelcars.com" },
      56. { "1143", "Bow", "Anthony", "x5428", "Sales Manager (NA)", "abow@classicmodelcars.com" },
      57. { "1165", "Jennings", "Leslie", "x3291", "Sales Rep", "ljennings@classicmodelcars.com" },
      58. { "1166", "Thompson", "Leslie", "x4065", "Sales Rep", "lthompson@classicmodelcars.com" },
      59. { "1188", "Firrelli", "Julie", "x2173", "Sales Rep", "jfirrelli@classicmodelcars.com" },
      60. { "1216", "Patterson", "Steve", "x4334", "Sales Rep", "spatterson@classicmodelcars.com" },
      61. { "1286", "Tseng", "Foon Yue", "x2248", "Sales Rep", "ftseng@classicmodelcars.com" },
      62. };
      63. /*********************************************************************
      64. *
      65. * Static code
      66. *
      67. **********************************************************************
      68. */
      69. /*********************************************************************
      70. *
      71. * _cbBk
      72. */
      73. static void _cbBk(WM_MESSAGE * pMsg) {
      74. int Id, NCode;
      75. WM_HWIN hListview;
      76. int Sel;
      77. char acBuffer [128];
      78. char acFirstName[32];
      79. char acLastName [32];
      80. switch (pMsg->MsgId) {
      81. case WM_PAINT:
      82. GUI_SetBkColor(GUI_WHITE);
      83. GUI_Clear();
      84. GUI_SetColor(GUI_BLACK);
      85. //
      86. // Display selected item
      87. //
      88. hListview = WM_GetDialogItem(WM_HBKWIN, GUI_ID_LISTVIEW0);
      89. Sel = LISTVIEW_GetSel(hListview);
      90. if (Sel != -1) {
      91. sprintf(acBuffer, "Selected row: %d", Sel);
      92. GUI_DispStringAt(acBuffer, 10, 380);
      93. LISTVIEW_GetItemTextSorted(hListview, ID_COLUMN_FIRST_NAME, Sel, acFirstName, sizeof(acFirstName));
      94. LISTVIEW_GetItemTextSorted(hListview, ID_COLUMN_LAST_NAME, Sel, acLastName, sizeof(acLastName));
      95. sprintf(acBuffer, "Selected employee name: %s %s", acFirstName, acLastName);
      96. GUI_DispStringAt(acBuffer, 10, 400);
      97. // LISTVIEW_DeleteRow(hListview,Sel);
      98. LISTVIEW_SetTextAlign(hListview,LISTVIEW_GetSelCol(hListview),GUI_TA_HCENTER | GUI_TA_VCENTER);
      99. }
      100. //
      101. // No selection
      102. //
      103. else {
      104. sprintf(acBuffer, "Selected row: none.");
      105. GUI_DispStringAt(acBuffer, 10, 380);
      106. }
      107. break;
      108. case WM_NOTIFY_PARENT:
      109. Id = WM_GetId(pMsg->hWinSrc);
      110. NCode = pMsg->Data.v;
      111. switch (Id) {
      112. case GUI_ID_LISTVIEW0:
      113. switch (NCode) {
      114. case WM_NOTIFICATION_SEL_CHANGED:
      115. //
      116. // Display new selection in this window when LISTVIEW selection has changed.
      117. //
      118. WM_InvalidateWindow(pMsg->hWin);
      119. break;
      120. }
      121. break;
      122. }
      123. break;
      124. default:
      125. WM_DefaultProc(pMsg);
      126. }
      127. }
      128. /*********************************************************************
      129. *
      130. * _CompareExtension
      131. */
      132. static int _CompareExtension(const void * p0, const void * p1) {
      133. const char * ps[2];
      134. int v[2];
      135. int i;
      136. ps[0] = (const char *)p0 + 1; // Move pointer by 1 to ignore the 'x'
      137. ps[1] = (const char *)p1 + 1;
      138. //
      139. // Parse to int
      140. //
      141. for (i = 0; i < 2; i++) {
      142. v[i] = atoi(ps[i]);
      143. if (v[i] == 0) {
      144. return 0;
      145. }
      146. }
      147. //
      148. // Return comparison result
      149. //
      150. if (v[0] > v[1]) {
      151. return -1;
      152. } else if (v[0] < v[1]) {
      153. return 1;
      154. } else {
      155. return 0;
      156. }
      157. }
      158. /*********************************************************************
      159. *
      160. * Public code
      161. *
      162. **********************************************************************
      163. */
      164. /*********************************************************************
      165. *
      166. * MainTask
      167. */
      168. //omer^aygor^1231244
      169. //omer serfa^dogruer^123123123
      170. void MainTask(void) {
      171. LISTVIEW_Handle hListview;
      172. int i;
      173. //
      174. // Init GUI
      175. //
      176. GUI_Init();
      177. //
      178. // Enable multi-buffering
      179. //
      180. WM_MULTIBUF_Enable(1);
      181. //
      182. // Set callback to background window to receive LISTVIEW notifications
      183. //
      184. WM_SetCallback(WM_HBKWIN, _cbBk);
      185. //
      186. // Create listview widget
      187. //
      188. hListview = LISTVIEW_CreateEx(10, 10, 400, 300, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTVIEW0);
      189. //
      190. // Add columns to listview
      191. //
      192. LISTVIEW_SetFont(hListview,&GUI_Font16B_1);
      193. LISTVIEW_SetHeaderHeight(hListview,40);
      194. LISTVIEW_AddColumn(hListview, 45, "Emp. Nr.", GUI_TA_LEFT);
      195. LISTVIEW_AddColumn(hListview, 60, "Last Name", GUI_TA_LEFT);
      196. LISTVIEW_AddColumn(hListview, 60, "First Name", GUI_TA_LEFT);
      197. LISTVIEW_AddColumn(hListview, 40, "Ext.", GUI_TA_LEFT);
      198. LISTVIEW_AddColumn(hListview, 110, "Title", GUI_TA_LEFT);
      199. LISTVIEW_AddColumn(hListview, 180, "Email", GUI_TA_LEFT);
      200. //
      201. // Add rows to listview
      202. //
      203. for (i = 0; i < GUI_COUNTOF(_acContent); i++) {
      204. LISTVIEW_AddRow(hListview, _acContent[i]);
      205. }
      206. //
      207. // Set compare functions
      208. //
      209. // LISTVIEW_SetCompareFunc(hListview, 0, LISTVIEW_CompareDec);
      210. // LISTVIEW_SetCompareFunc(hListview, 1, LISTVIEW_CompareText);
      211. // LISTVIEW_SetCompareFunc(hListview, 2, LISTVIEW_CompareText);
      212. // LISTVIEW_SetCompareFunc(hListview, 3, _CompareExtension);
      213. // LISTVIEW_SetCompareFunc(hListview, 4, LISTVIEW_CompareText);
      214. // LISTVIEW_SetCompareFunc(hListview, 5, LISTVIEW_CompareText);
      215. //
      216. // Enable sorting
      217. //
      218. LISTVIEW_EnableSort(hListview);
      219. LISTVIEW_SetGridVis(hListview,1);
      220. //
      221. // Enable motion scrolling
      222. //
      223. LISTVIEW_EnableMotion(hListview, LISTVIEW_CF_AUTOSCROLLBAR_H | LISTVIEW_CF_AUTOSCROLLBAR_V);
      224. HEADER_Handle hHeader = LISTVIEW_GetHeader(hListview);
      225. HEADER_SetTextColor(hHeader, GUI_RED);
      226. HEADER_SetFont(hHeader,&GUI_Font16B_1);
      227. int memsize = 1024 * 1024;
      228. char *fContect = malloc(memsize * (sizeof(char)));
      229. if( fContect == NULL )
      230. {
      231. PRINTF("Malloc Error!\n");
      232. }
      233. while (1){
      234. GUI_Delay(100);
      235. sysDelay(1000);
      236. int numOfRead = LISTVIEW_GetUserData(hListview,fContect,memsize);
      237. PRINTF("numOfRead:%d.\n",numOfRead);
      238. }
      239. }
      240. /*************************** End of file ****************************/
      Display All
    • Hi,

      The user data set to windows or widgets refers to additional data being allocated when the window/widget is created. This data is part of the memory block associated with the window and can be accessed with <WIDGET>_GetUserData(). You can find a detailed tutorial about this topic in our wiki.

      The strings added to a LISTVIEW are not part of the user data. And since you did not add user data to the widget with LISTVIEW_SetUserData() calling ..._GetUserData() returns 0 bytes.

      Unfortunately the LISTVIEW does not offer a CSV import/export feature. But we will discuss this internally, as it can be very useful indeed.

      BTW: In line 232 you pass the LISTVIEW_CF_AUTOSCROLLBAR_... flags to LISTVIEW_EnableMotion(). This won't have any effect, you have to use the LISTVIEW_CF_MOTION_... flags instead.

      Best regards,
      Florian
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.